开发者

From a list of li, how do I tell which one is active using jquery?

开发者 https://www.devze.com 2023-04-10 09:55 出处:网络
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

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

精彩评论

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

关注公众号