user2669989
user2669989

Reputation: 270

check jQuery object content returned by $(document).ready()

When we write a jQuery function like $(document).ready() which return an jQuery Object, how to check whether the Object returned is empty or any content inside it (like is there any jQuery function for that)

Upvotes: 0

Views: 95

Answers (2)

RGS
RGS

Reputation: 5211

You can check the element available or not through .length property.

$(document).ready(function () {
 if($('#spnText').length>0) {  
 } 
});

HTML:

<span id="spnText"/>

Upvotes: 2

Robban
Robban

Reputation: 6802

You could just look at the .length property of the returned object.

For example:

$('div').length;

Upvotes: 1

Related Questions