• item 1
  • item 2...">
    All geek questions in one place

    JQuery: not () issue

    jQuery 1.4:

    $('#menu li:last:not(.ignore)').addClass('last');
    

    HTML:

    <div id="menu">
        <ul>
            <li>item 1</li>
            <li>item 2</li>
            <li class="ignore">item3</li>
        </ul>
    </div>
    

    .. the lastclass does not apply to item 2. What am I doing wrong here?

    thank

    +3
    jquery selector
    3zzy Mar 01 '10 at 14:07
    source share
    3 answers

    Change the order :lastand :not():

    $('#menu li:not(.ignore):last')
    
    +5
    Gumbo Mar 01 '10 at 14:08
    source share

    How does your expression work:

    • Find the item with the identifier "menu";
    • Find all elements of the descendant list of this element;
    • Limit the results to the very last element in this set;
    • Filter out elements (this is only one element of this point, the last) that do not have a class of "ignore".

    The last element has an ignore class, so it is filtered out. That is why it does not work. Reorder:

    $("#menu li:not(.ignore):last").addClass("last");
    
    +2
    cletus 01 . '10 14:10

    , , : " .ignore":

    // tested
    $("#menu li.ignore:first").prev("li").addClass('last');
    
    0
    karim79 01 . '10 14:17

    Source: https://habr.com/ru/post/1734883/

    More articles:

    • https://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1734878/best-uidesign-patterns-to-find-my-users-friends-who-are-also-my-users&usg=ALkJrhjjvn6rvBg60rgo2DrS5akfUZuhWQ
    • В какой момент импорт становится правильным решением? - python
    • Weird Javascript Bug (jQuery) in a simple test page - javascript
    • https://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1734881/shared-authentication-between-saascloud-web-application-and-desktop-application&usg=ALkJrhgFtuQyz3wy25bfbS_7Mvhb8SaFNg
    • how to activate a trigger after all voluminous inserts in mysql - mysql
    • NPTL binding for pthread pthread_condattr_setclock - pthreads
    • DOS to execute all SQL scripts in a directory and subdirectories - sql
    • How do you live - filter NSArray or NSMutableArray? - cocoa
    • ASP.NET/JavaScript - Ajax call, how? - javascript
    • JFace Label Provider Overview - eclipse

    All Articles

    Geek Questions | 2019