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:
$("a[href$='.jpg']").parent().prev().addClass("Image");
First it navigates to the parent element of the selected element and then to the nearest sibling before that element, thus reaching the div element you require.
See the documentation on parent and prev for more details.
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