Say I do
var s = $(\'#something\');
and next I want to test if jQuery found #something, i.e. I want to test if s
is empty.
An even more jQueryesque solution for me is:
jQuery.fn.isEmpty = function(fun){ if (this.length === 0) { fun(); } return this; };
This lets me write in typical fashion:
$("#sel").fadeOut(500,afterFade).isEmpty(insteadOfFade);
if($("#something").length > 0 ){
// Element found
}
else{
// No element found
}
Use the s.length property.
if(s.length == 0) {
...
}
[edit] size() deprecated in jquery 1.8 http://api.jquery.com/size/