Alex Rivera | Logout

Finding appropriate parent with jQuery

Asked 2008-12-18T15:14:59.043
16

Given a DOM element how do I find its nearest parent with a given css class?

$(".editButton").click(function() {
   (magic container selector goes here).addClass("editing");
});

I don't want to use lots or $(...).parent().parent() since I don't want to be bound to a particular dom structure.

Edit
Report

1 Answer

2

You can use the parent selection. eg $(".myclass:parent").something(); will find all the elements with the class myclass that have children.

answered 2008-12-18T15:22:06.563

Your Answer