开发者

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜