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
the sample page has been updated... the answer should be....
var $li = $("ol#newlist > li").add(
$('#newlist').children('li').children('ol').filter(function() {
return $(this).children().length > 1;
}).children()
);
$li.show();
or
var $li = $('#newlist').find('li').filter(function() {
return ($(this).siblings('li').length );
});
$li.show();
as answered by patrik...
Thanks for the help...
Thanks
Pradyut
India