Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

$(window).click(function(e) - identifier of currently clicked element

$(window).click(function(e) {
    alert(e.???);
});

How can I check how id, class or other identifiers of the current click?

like image 924
Mark Fondy Avatar asked Jan 16 '12 02:01

Mark Fondy


1 Answers

The event object gives you a target property that refers to the actual element clicked, and a currentTarget property that refers to the element to which the handler was bound.

Those elements are represented as DOM nodes, which are just objects with their own properties, which enable to you to access certain aspects of the state of the element.

$(window).click(function(e) {
    alert(e.target.id); // gives the element's ID 
    alert(e.target.className); // gives the elements class(es)
});
like image 132
2 revsuser1106925 Avatar answered Oct 12 '22 11:10

2 revsuser1106925