Reputation: 57
How can I use jQuery when I have this HTML code I need to add the class name to the parent li only when the child has the class name high.
thanks.
<li class="emergency" style="background-color: #FE9D9D;">
<span class="high">250</span></li>
Upvotes: 0
Views: 68
Reputation: 3109
$(".high").parent().addClass('sss');
jsfiddle http://jsfiddle.net/M5gNA/
Upvotes: 0
Reputation: 16544
If I understand the question correctly, you want to add the class of the span
also to the parent li
, right?
$('li .high').closest('li').addClass('high');
Upvotes: 0
Reputation: 57105
Use .has()
$('li:has("span.high")').addClass('className');
li has
span element with class high
addCass className
to it.
Upvotes: 1
Reputation: 32581
You can target .high class like this then use closest() to get the parent li.
$('li .high').closest('li').addClass('myClass');
Upvotes: 2