Suppose I have created one jQuery function to check if elements exist or not like:
jQuery.fn.exists = function () {
return this.length > 0;
}
Then I call:
if ($("#MyDiv").exists() == false)
alert('not exist');
else
alert('exist');
If I call jQuery function above it works. But can’t we call the jquery function like this way exists('#MyDiv') ? If I try to call this way then I am not getting result…why?
Try like below,
and use as,
DEMO: http://jsfiddle.net/skram/hgaPt/1/
Please use this in a bigger picture, using it for simple thing as exist is just a overkill.