Search results
7 wrz 2008 · You can use event.target.id in event handler to get id of element that fired an event. In jQuery event.target always refers to the element that triggered the event, where event is the parameter passed to the function. http://api.jquery.com/category/events/event-object/ $("a").click(function(event) { alert(event.target.id); });
The target property returns the element on which the event occurred, opposed to the currentTarget property, which returns the element whose event listener triggered the event. See Also: The currentTarget Property
27 mar 2022 · To get the id attribute of a DOM element on click, create an event listener using AddEventListener() and retrieve the id of the clicked object using Element.target().
20 mar 2021 · We call window.addEventListener to attach the click event listener to the html element. Then we get the element that’s clicked on from the event.srcElement property. And we can get the ID of that element with the id property.
This tutorial provides you the method of getting the id of the element fired an event in jQuery. Read about the event.target property and this keyword.
You can use the event.target property to get the ID of the element that fired an event in jQuery. This property always refers to the element that triggered the event. The following example will display the name of the element that was just clicked. div, p, span{ padding: 30px; display: block; . border: 3px solid #999;
20 sty 2013 · To get the attribute of a target element in JavaScript you would simply use: e.target.getAttribute('id'); See also: https://stackoverflow.com/a/10280487/5025060 for the subtle distinction between DOM properties and their attributes.