doesExist
jQuery Plugin
Tired of calling $('div').length > 0 ?
Need to call it over and over again ?
There comes my solution: doesExist().
The plugin returns true or false if the element exists or not.
Stop using long if conditionals, simply use doesExist().
Michael Stadler
Code:
- $.fn.doesExist = function(){
- return jQuery(this).length > 0;
- }
Including:
- <head>
- .
- .
- .
- <script src="jquery.doesExist.js" type="text/javascript"></script>
- </head>
or:
- <body>
- .
- .
- .
- <script src="jquery.doesExist.js" type="text/javascript"></script>
- </body>
Usage:
- $('#myDiv').doesExist(); //returns true or false
Demo:
Result Area:
Author:
Michael Stadler is a full-time employed IT Consultant, located in Vienna.
He focuses on jQuery development and has worked in many projects including CMS Systems like Content Lion.
As this would not be enough, he is also working as a paramedic for the austrian red cross.
Any questions or support requests ? Go to evilwebdesign.bplaced.net.
He focuses on jQuery development and has worked in many projects including CMS Systems like Content Lion.
As this would not be enough, he is also working as a paramedic for the austrian red cross.
Any questions or support requests ? Go to evilwebdesign.bplaced.net.