How to Determine if an Element Exists with jQuery?
jQuery makes it easy to determine if an element in your DOM exists.
if ( $('#elementID').length )
{
// do something
}
Simple enough, right?
2 notes / Permalink
jQuery makes it easy to determine if an element in your DOM exists.
if ( $('#elementID').length )
{
// do something
}
Simple enough, right?
2 notes / Permalink
It’s simple really…
$("img", this);
The above jQuery translation is just a short version of
$(this).find("img");
So using the find() method would be a touch faster, but both accomplish the same task.
This differs from the standard selection of a child element which is:
$(div > img);
1 note / Permalink
To see if an element exists in jQuery you simply need to check for a length
$("#myElement").length
If the above ID has a length the statement returns true.
Tested in jQuery v1.4.2
1 note / Permalink