jquery get the parent element’s id

You could use event delegation on the parent div. Or use the closest method to find the parent of the button.

The easiest of the two is probably the closest.

var id = $("button").closest("div").attr("id");
var id = $("button").parent().attr("id");

By Keenlio, February 17, 2014

What do you think?

Leave a Reply

Your email address will not be published. Required fields are marked *


9 − six =

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>