简体   繁体   中英

filter array of list into sub array in jquery

I am stuck at code, i have a array of li's element and i want another array which contains li from ist array which has classname hide. here is what i am trying

<div id="videoarea ">
  <ul>
    <li class="hide">a</li>
    <li class="hide">a</li>
    <li class="hide">a</li>
    <li >a</li>
    <li >a</li>
    <li >a</li>
  </ul>
  <ul>
    <li class="hide">b</li>
    <li class="hide">b</li>
    <li class="hide">b</li>
    <li >b</li>
    <li >b</li>
    <li >b</li>
  </ul>
</div>
var items = $("#videoarea div ul");

var templi = items.eq(1).children().hasClass("hide"); // it is only showing true, i want array of li's having class hide

I want an array which contains li's of particular ul having class hide and if possible another array which dont have class hide

For li elements with .hide , simply connect them in a selector.

For li elements without .hide , use :not()

var items = $("#videoarea div ul");

var liWithHide = items.eq(1).children("li.hide"); 
var liWithoutHide = items.eq(1).children("li:not(.hide)"); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM