[jQuery] Find first matching previous element relative to (this)
Hi, I'm trying to target the closets instance of an element with a
class name target but I'm having trouble figuring out how to do this.
So given this HTML
<p class="target">how are you?
hello
<p class="target">how are you? <-- want to target this paragraph
I am fine
<div>
<div class="btn">button</div>
</div>
I'm trying to use something like the following to find the closest
previous "target" element to "btn".
$(".btn").click(function(){
$(this).find(".target:first").css('color','red');
});
Any ideas?