I have troubles to get the parent id of elements.
$(function(){
$("#elem-132224").append("<button class='sum'>+</button><button>-</button>")
$(".sum").click(function(){
alert($(this).attr('id'));
})
why is not working?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It doesn’t work because the button doesn’t have an
id. It merely hasclass. You can write it like this:If you want to get the parent
id(the element which<button>is inside it), you can useparent()in jquery: