How does the jQuery tag $(this)
exactly work? I know how to use it, but how does jQuery know which element is 'active'? And what is the original Javascript tag for getting the current item, or is it jQuery only?
The this
is a simple javascript (DOM) object,
$(this)
will turn the object into a jQuery object.
jQuery doesn't need to 'know' what this
is, it doesn't treat this in a special way, no other than myHeaderDiv
in
var myHeaderDiv = document.getElementById('header');
$myHeaderDiv = $(myheaderDiv); //just a variable transformed into jQuery object, as with this.
this
is context-dependent in jQuery (and JavaScript in general). It usually represents the current DOM element in a event handler, but is not a jQuery object.
$(this)
is a jQuery object containing the current DOM element.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With