开发者

Check that element is in DOM or not with jQuery?

开发者 https://www.devze.com 2023-03-29 10:34 出处:网络
I have quick and simp开发者_StackOverflow社区le question. How can I check that an element is in the DOM or not?

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
}
0

精彩评论

暂无评论...
验证码 换一张
取 消