Reputation: 270
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
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
Reputation: 6802
You could just look at the .length
property of the returned object.
For example:
$('div').length;
Upvotes: 1