abhi
abhi

Reputation: 1084

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

Upvotes: 0

Views: 222

Answers (1)

AmmarCSE
AmmarCSE

Reputation: 30557

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)"); 

Upvotes: 2

Related Questions