I’m a bit confused on how to properly select a parent item, that is 2 DIV’s up.
In other words, my HTML looks like this:
<div>Folder</div>
<div class="file_info">
<a href="test.jpg">Test File</a>
</div>
Here’s my current jQuery: $("a[href$='.jpg']").addClass("Image");
However, I don’t want to add the class to the <a>, instead, I want to add the class to the ‘folder’ 2 DIV’s above.
What’s the best way to do this?
Thanks!
This will work:
First it navigates to the parent element of the selected element and then to the nearest sibling before that element, thus reaching the
divelement you require.See the documentation on parent and prev for more details.