开发者

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')){

    }
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜