$ (window) .click (function (e) - identifier of the element with the click at the moment

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

How to check identifiers, class or other identifiers of the current click?

+6
source share
2 answers

The event object gives the target property, which refers to the actual click of the element, and the currentTarget property, which refers to the element to which the handler is bound.

These elements are represented as DOM nodes, which are simply objects with their own properties that allow you to access some aspects of the state of an element.

 $(window).click(function(e) { alert(e.target.id); // gives the element ID alert(e.target.className); // gives the elements class(es) }); 
+8
source

http://api.jquery.com/category/events/

and look at the event. * - 17

or console.dir(e); instead of alert(e); to see what you have ...

 $(window).click(function(e) { console.dir(e); }); 
+4
source

Source: https://habr.com/ru/post/906068/


All Articles