From a list of li, how do I tell which one is active using jquery?
From a list of li, how do I tell which one is active with a highlight class using jquery?
For example, I have the ul list
<ul>
<li> 11111111 </li>
<li> 22222222 </li>
<li> 33333333 </li>
<li> 44444444 </li> <---- highlighed white/black by (.highlight) 开发者_如何学Cclass
<li> 55555555 </li>
</ul>
the selector would be:
$('li.highlight')
or if you loop through the LIs and want to check if it's active you can use .is()
$('li').each(function(){
if($(this).is('.highlight')){
}
});
$('li:contains(44444444)').addClass('highlight')
$("li.highlight")
will select the active element
you could do
$('li').each(function(){
if($(this).hasClass('highlight')){
}
});
精彩评论