I need to get number of li element inside a ul. in fact i want to perform specific action when a ul has no child. is there any way to do that with jquery?
Asked
Active
Viewed 153 times
-6
hamed
- 7,681
- 13
- 50
- 104
-
2Yes there is. What have you tried – PW Kad Jan 06 '15 at 06:57
1 Answers
0
You can use .has() selector:
if(!$('ul').has('li')){//ul is empty
}
Milind Anantwar
- 79,642
- 23
- 92
- 120
-
-
-
1@PWKad: i understand. but should not the question be downvoted rather than answer. – Milind Anantwar Jan 06 '15 at 07:01
-
I downvoted them all. It's a poor question that is a duplicate and a poor answerer who chooses to give a half-way answer rather than flag a duplicate. – PW Kad Jan 06 '15 at 07:06