• Clever Geek Handbook

    JQuery: how to create a double.not () statement?

    I have 3 layers of nested menus in <ul>

    s, for example:

    <div id="menu">
        <ul>
        <li><a href="somewhere.html">enu Item</a>
          <ul>
            <li><a href="somewhere.html">Menu Item 2</a>
                <ul>
                   <li><a href="somewhere.html">Menu Item 3</a></li>
                 </ul>
            </li>
          </ul>   
        </li>
        </ul>
    </div>
    
          

    I want to use Jquery to replace the first level href attribute ul

    with #, but keep the href attributes in the 2nd and 3rd tags.

    Ive created this script that works for 2nd level ul

    but not 3rd level.

    $("#menu ul li a").not("#ctamenu ul li ul a").attr("href", "#");
    
          

    I've tried this:

    $("#menu ul li a").not("#menu ul li ul a").not("#menu ul li ul li a").attr("href", "#")
    
          

    But it doesn't work - on the third level there is href='#'

    Is there a way to make the expression "double not"?

    +3
    javascript jquery jquery-selectors attributes


    MeltingDog 18 Feb 13 at 2:13
    source to share


    2 answers


    The third level is nested within another one ul

    you are missing, but it would be easier to use a child selector:



    #menu > ul > li > a
    
          

    +6


    Explosion pills 18 Feb '13 at 2:16
    source to share


    Depending on your situation, you might find it helpful to create an add class="first-level"

    for the first level anchor tags. You can then use $('.first-level')

    , which is more convenient as your menu logic becomes more level-dependent.



    0


    Alex williams 18 Feb At 2:51 am
    source to share






    More articles:

    • webViewLink now returns "404 Not Found" - google-drive-sdk
    • Garbage at the end of `NSString` on xCode after calling stringByReplacingCharactersInRange` - objective-c
    • what causes the asp.net out of memory exception - c #
    • 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/1999130/how-can-i-remap-one-json-lines-to-hierachycal-json&usg=ALkJrhjFKbxuwb41R5dpSMFK7YD2q4XH3A
    • Rails gem ckeditor загружает пользовательские config.js перед его собственной конфигурацией - ruby-on-rails
    • Why am I getting an error on this line? - c #
    • ajax and javascript problems when trying to count labels - javascript
    • Nested Models Form Rails 3 - ruby-on-rails
    • Floating point limit code not giving correct results - c ++
    • Как вставить DateTime (или DateTime2) в Dapper? - c#

    All Articles

    Daily Blog | 2020

    Green Geek Media (GGM)
    1298 Despard Street
    GA 30344 East Point, USA
    404-763-3837