not able to get a processed list in jquery variable

Posted by Pradyut Bhattacharya on Stack Overflow See other posts from Stack Overflow or by Pradyut Bhattacharya
Published on 2010-04-23T22:05:28Z Indexed on 2010/04/23 23:03 UTC
Read the original article Hit count: 326

I have html list

<ol id="newlist">
        <li>Test
            <ol>
                <li>1</li>
                <li>2</li>
                <li>3</li>
            </ol>
        </li>
        <li>Another test
            <ol>
                <li>1</li>
            </ol>
        </li>
        <li>Cool Test
            <ol>
                <li>1</li>
                <li>2</li>
            </ol>
        </li>
    </ol>

Now i have hidden the list using the css...

        #newlist li {
            display:none;
            list-style: none;
        }

I want to display the list and the only the descendants which have greater than 1 descendants...

the output should be...

Test
   1
   2
   3
Another test
Cool Test
   1
   2

I have used jquery and able to get the output...

the code i used...

   $("ol#newlist > li").show();


            for (var i = 0; i < $("ol#newlist > li").length; i++)
            {
                if ($("ol#newlist > li:eq(" + i + ") ol > li").length > 1)

                $("ol#newlist > li:eq(" + i + ") ol > li").show();


            }

the sample page here

Now i want all the list in a single variable like i can get the lis in a variable...

      var $li = $("ol#newlist > li");

but the code

      $li.add($("ol#newlist > li:eq(" + i + ") ol > li"));

is not working...

the sample page here

Please help...

Thanks
Pradyut
India

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about html-lists