Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to judge whether selected result is empty or not with jQuery?

$("#experiences tr")

For the above one,how to judge if it's empty or not?

I thought its boolean value should be false,but seems not.

like image 930
omg Avatar asked Aug 27 '09 07:08

omg


People also ask

How check selector is empty in jQuery?

The is() method is used to check if one of the selected elements matches to the selector element. This method can be used on this element to test if it is empty by using “:empty” selector. The “:empty” selector is used to select all the elements that have no children.

Is empty in jQuery?

The empty() method removes all child nodes and content from the selected elements. Note: This method does not remove the element itself, or its attributes. Tip: To remove the elements without removing data and events, use the detach() method. Tip: To remove the elements and its data and events, use the remove() method.

How do you check the div is empty or not?

Use the childNodes property to check if a div element is empty. The childNodes property returns a NodeList of the element's child nodes, including elements, text nodes and comments. If the property returns a value of 0 , then the div is empty.


2 Answers

use the length property:

$("#experiences tr").length 

if it's 0 it's empty

like image 105
mck89 Avatar answered Sep 20 '22 23:09

mck89


var experienceRows = $('#experiences tr'),     len = experienceRows.length;  if ( len ) { } else { } 
like image 36
meder omuraliev Avatar answered Sep 19 '22 23:09

meder omuraliev