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.
This should work
$(this).parents('.classYouWant:first').addClass("editing");
$( this ).closest( '.yourselector' )
As the name tells, finds the closest ancestor for this
element.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With