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

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -