jQuery on() Method: This method adds one or more event handlers for the selected elements and child elements. Use e.currentTarget || e.srcElement only for divs and stuff that have children below. I'm trying to code a simple game in an HTML document just for fun. Example Click Continue to enable the API and any related services. If RenderTreeBuilder code is written, the developer must guarantee the correctness of the code. function myFunc(Stack Overflow. You mustn't send the element id by yourself such as onClick="myFun(btn02)". ; Attributes are only added in the correct places. You can get a button ID during a click event thanks to the target property of the Event interface. So before use, you need to make sure that your element already has an id. How to get only the element I clicked on? So in your example, even if you didn't have any other explicitly clickable elements in the div, every child element of the div would bubble their click event up the DOM to I would like to get the current element (whatever element that is) in an HTML document that I clicked. Xiaodan Mao. Syntax: it's not CLEAN Use e.currentTarget || e.srcElement only for divs and stuff that have children below. Your code clickedElement.closest('.delete'); could fail if you have multiple nested elements with this class. It's a bit different. I am using: $(document).click(function { alert($(this).text()); }); But very strangely, I get the text of the whole(!) Unfortunately this still fetches the element twice, which is not ideal. In case your element doesn't have children you can safely use target always. That whole if section is executed only on IE. The function takes two arguments in which the first is the index position of the element and the second argument is the number of elements to remove. The element will be sorted in the collection. I need to get all the input objects and manipulate the onclick param. About; Products @jpo In onclick="javascript: myFunc(myID)", myID should be wrapped by single quotes. In IE there is only a global selection, that's why it's document.selection, not field.selection or something. Use .querySelector() method on parent. Vlatko Vlahek It can be easily bypassed using the DOM, for example by creating a hidden