I'm not able to get the

问题描述 投票:0回答:1
to work. I want to check if the

has a nested $.contains(arg1, arg2)

but no matter what format I put the arguments in I always get an output of $.contains(). (want to eventually wrap that in a if statement to edit some CSS) <li>More info below<ul class="sub-menu">JSfalseHTML

Here I want to be able to conditionally edit css using Js + Jquery (the Codepen has the basic css)

Codepen (Just for reference :)))

$( document ).ready(navSecondary());
function navSecondary(){
  var firstListSize = $("nav.header-secondary>ul>li").length;
  for (var i = 0; i < firstLiSize; i++) {
    var nav = $("nav.header-secondary>ul>li:nth-child("+i+1+")");
    var sub = document.documentElement.getElementsByTagName("ul");
    var check = $.contains(sub,nav);
    console.log(check);
  }
}

Some background

<nav class="header-secondary">
    <ul>
        <li><a href="#">item 1</a>
            <ul class="sub-menu">
                <li><a href="#">Sub Option 1</a></li>
                <li><a href="#">Sub Option 2</a></li>
                <li><a href="#">Sub Option 3</a></li>
            </ul>
        </li>
        <li><a href="#">Item 2</a></li>
        <li><a href="#">Item 3</a></li>
    </ul>
</nav>

So I'm creating a theme on WordPress and want to use WordPress's inbuild menu manager, I don't want to go through the hassle of asking WordPress to create classes for each list item and sub menu list so on and so forth. EDIT- I realize there is an easier way to do the CSS (through the classes WordPress would add to the menu items) but I wanted to try and do it through Jquery

Main issue

javascript html jquery dom conditional-formatting
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.