Check that element is in DOM or not with jQuery?
I have quick and simp开发者_StackOverflow社区le question. How can I check that an element is in the DOM or not?
For example how can I check if there is
<p id="does_i_really_exist_or">this is just matrix</p>
if ( $("#does_i_really_exist_or").length ) {
//-- It does exist.
}
if ($("#does_i_really_exist_or").length > 0) {
// do something
}
here are three different ways:
if ($("#does_i_really_exist_or").length > 0) {
// do something
}
if ($("#does_i_really_exist_or").size() > 0) {
// do something
}
if ($("#does_i_really_exist_or")[0]) {
// do something
}
精彩评论