tags:

views:

36

answers:

4

Hi I have shared the code here : http://jsfiddle.net/jTAZ4/

Why am i getting the length as 0 although I can see an li with the specified class. any help is deeply appreciated.

I know this will work with find but just wondering why children selector doesn't work.

+3  A: 

That's because the <li> is not a direct children of that <div>.

You should use .find() instead of .children().

KennyTM
well i knew i had to use find but i dint know .children just searched for elements single level down
+1  A: 

.children() only selects direct children. Try .find() instead.

elusive
A: 

Try using .find('.jstree-leaf') instead of .children('.jstree-leaf').

Ken Redler
A: 

You have to use .find() instead of .children()

alert($('div.round').find('.jstree-leaf').length);

.children() only searches one level deeper and skips all the elements in deeper levels.

softcr