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 - ScrollTo Effect (href to div) -

javascript - ng-class not responding to change in model in Angular? -

javascript - document.registerElement extending HTMLInputElement prototype while using custom tag name to avoid implicit browser style -