Hello, I have a structure like this:
<ul id="mycustomid">
<li><a>Item A</a>
<ul class="children">
<li><a>Child1 of A</a>
<ul class="children">
<li><a>Grandchild of A</a>
<ul class="children">
<li><a>Grand Grand child of A</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
<li><a>Item B</a></li>
<li><a>Item C</a></li>
</ul>
Now, I am using Jquery to get only the immediate children of the ul#mycustomid. But my code returns me with ALL the li's in my structure. How should I proceed?
Here's my code:
$(document).ready(function() {
var arri = $("#mycustomid>li").text();
alert(arri);
});
I have tried .children() too, it gives me almost the same result. This is really getting on my nerves :(
My alert box outputs exactly as shown below (including those white gaps):
Item A
Child1 of A
Grandchild of A
Grand Grandchild of A
ItemBItemC
Whereas, it should be just (without spaces):
Item A
Item B
Item C
To understand my problem, you can check out the live version at http://jsfiddle.net/yS6ZJ/
Please point me in the right direction,
Thanks