Is there a way to get JavaScript this from jQuery this?
There is:
$('a').click(function(){
var jqueryobject = $(this);
var domelement = this;
});
Within such a closure, this
always represent the native DOM element
which must/can be wrapped
into a jQuery object.
If you already got a jQuery object and need to get the DOM element
either use
var DOMelement = $(this)[0];
or
var DOMelement = $(this).get(0);
Since jQuery objects are array like objects
you can always grab them with standard array access []
notation. The jQuery method .get() will actually do the same. With both ways, you'll receive the DOM element
at that array position.
General - what is this
?
this
contains a reference to the object of invocationthis
allows a method to know what object it is concerned withthis
allows a single function object to service many functionsthis
is the most important part of all protoypal inheritance things