I looked up the whole jQuery Docs, but i doesn't found anything: Is it possible to search an element before the current one with a specific class? I thought this will work, but it doesn't:
$(this).prev('.bar');
http://jsfiddle.net/Ejh5G/
Try:
$('.d').prevAll('.a').css('color','red');
Fiddle
To address Jan's point, you can do this:
$('.d').prevAll('.a').first().css('color','red');
Use .prevAll() :
$(this).prevAll('.bar');// all elements
$(this).prevAll('.bar').eq(0); //first element
$(this).prevAll('.bar:last'); //last 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