开发者

jQuery .not() function, not working

开发者 https://www.devze.com 2022-12-08 22:42 出处:网络
$(\".navigation a\").not(\".navigation ul ul a\").hover(function(){ // Not working. }); For some reason, ALL <a> elements inside .navigation still get the hover function assigned to it.开发者

$(".navigation a").not(".navigation ul ul a").hover(function(){

    // Not working.

});

For some reason, ALL <a> elements inside .navigation still get the hover function assigned to it.开发者_如何学C

I only want the elements that are not inside ul ul.

The Html is structured like this:

<div class="navigation">
    <ul>
        <li><a>item 1</a></li>
        <li><a>item 2</a></li>
        <li>
            <a>item 3</a>
            <ul>
            <li><a>item 3.1</a><li>
            <li><a>item 3.2</a><li>
            <li><a>item 3.3</a><li>
            </ul>
        </li>
        <li><a>item 4</a></li>
        <li><a>item 5</a></li>
    </ul>
</div>


$('.navigation > ul > li a')


try

$(".navigation>ul>li>a");

This will select anchors that are direct descendants of li's which are direct descendants of ul which are direct descendants of .navigation


Maybe this will work

$(".navigation a").not("ul ul a").hover(function(){
});


Try this:

$(".navigation a").not("ul ul a").hover(function(){ });
0

精彩评论

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