PDA

View Full Version : [javascript + jQuery]Ottenere l'oggetto che ha chiamato l'evento


Mattyfog
29-01-2011, 12:25
Ho il codice seguente:
$(".mouseEnter").mouseenter(function(){};
Come posso ottenere l'oggetto che ha chiamato l'evento, ossia l'oggetto che appartiene alla classe .mouseEnter?
Grazie!

kk3z
30-01-2011, 12:50
documentazione:
The handler parameter takes a callback function, as shown above. Within the handler, the keyword this refers to the DOM element to which the handler is bound. To make use of the element in jQuery, it can be passed to the normal $() function. For example:

$('#foo').bind('click', function() {
alert($(this).text());
});


$(".mouseEnter").mouseenter(function(){
alert($(this).attr("class"));
});