Reputation: 33
I have a list of items like this:
<div class="wine"> <H1>Title</H1> <div class="promotion"></div></div>
<div class="wine"> <H1>Title</H1> </div></div>
<div class="wine"> <H1>Title</H1> </div></div>
<div class="wine"> <H1>Title</H1> <div class="promotion"></div></div>
When the div .promotion exists in the wine dive i want to give the wine class a red border. But only for that element of course not for all the wine classes..
Anyone have an idea?
Upvotes: 0
Views: 58
Reputation: 38112
Please note that you need to remove redundant closing </div>
tag after second and third <div class="wine">
to make your HTML markup correct.
After that, you can use .closest():
$('.promotion').closest('.wine').css('border','1px solid red');
Upvotes: 1
Reputation: 148150
You can use .has() method on .wine
to check if it has .promotion
$('.wine').has('.promotion').css('border', 'red 1px solid');
Upvotes: 0
Reputation: 10180
You can use the .parent()
selector to do this like so:
$('.promotion').parent('.wine').css('border', 'red 1px solid');
Here is a fiddle showing it off: http://jsfiddle.net/33Ugf/
Upvotes: 2