Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does this work in jQuery?

I'm trying to understand why something works the way it does in jQuery. When I want to apply a jQuery extension, for example datatables, I run the command:

$("#some_id").datatables(.. parameters ..);

I don't know why this works, obviously the DOM element didn't have a method datatables() beforehand.

Thanks!

like image 668
Ben Avatar asked Feb 10 '26 09:02

Ben


1 Answers

$("#some_id") does not return a HTML DOM element, it returns a JQuery object wrapping it.

This JQuery object does have the datatables method.

like image 127
Andrew Stubbs Avatar answered Feb 13 '26 08:02

Andrew Stubbs



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!