closest()
will get the first element that matches the selector by testing the element itself and traversing up through its ancestors in the DOM tree. But I want
Vanilla js:
el.parentElement.closest('.container')
Jquery:
el.parent().closest('.container');
If you truly want only parent divs, then yes $(this).parents('.container') would work. If you want to look for the closest element and allow for it to be a sibling (which it seems might be what you are actually trying to accomplish) you can use $(this).prev('.container').
You can traverse a level up before trying to find the .closest()
ancestor:
$(this).parent().closest('.container');
The right answer is .parents('.container:first');
thanks