Baz1nga
Baz1nga

Reputation: 15579

jquery children selector issue

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.

Upvotes: 2

Views: 311

Answers (4)

softcr
softcr

Reputation: 620

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.

Upvotes: 0

Ken Redler
Ken Redler

Reputation: 23943

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

Upvotes: 0

jwueller
jwueller

Reputation: 30996

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

Upvotes: 1

kennytm
kennytm

Reputation: 523304

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

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

Upvotes: 3

Related Questions