Nelle funzioni jQuery, this
si riferisce più spesso all'elemento DOM reale con cui si ha a che fare, mentre $(this)
restituisce un oggetto jQuery che avvolge l'elemento.
In JavaScript, this
fa sempre riferimento all'ambito corrente. Molte delle funzioni di jQuery imposteranno quell'ambito per essere l'elemento con cui stai lavorando.
Per esempio
$("#someElement").click(function() {
this; // the element itself
$(this); // a jQuery wrapper-object around the element
});
Il punto è, che l'oggetto jQuery ha tutte le funzioni jQuery (come .detatch()
o .prependTo()
ecc), mentre l'elemento DOM è ciò che il browser fornisce. Nell'esempio sopra, l'elemento sarebbe esattamente lo stesso di quello che otterresti, se hai chiamato document.getElementById("someElement")
http://stackoverflow.com/questions/1051782/jquery-this-vs-this –
Mille grazie ragazzi! È molto più chiaro ora. – user864600