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();
Comments
Post a Comment