javascript - Jquery selects too many elements on mouseclick -


i want id of element click. should give me id if has one.

i have code alert me element id:

$("[id]").click(function(event) {     event.preventdefault();     var id_name = $(this).attr("id");     alert(id_name); }); 

but want foremost element's id.

i have button inside div, both id-attribute. if click button, want id of button. however, script alerts me of both buttons id , div's id. why that/how can foremost element's id?

thats because when click button, clicking parent element.

add within function event.stoppropagation();

http://api.jquery.com/event.stoppropagation/


Comments

Popular posts from this blog

javascript - How to synchronize the Three.js and HTML/SVG coordinate systems (especially w.r.t. the y-axis)? -

javascript - How do I find how many occurences are there of a highlighted string, and which occurence is it? -

java - Reading data from multiple zip files and combining them to one -