How to check a div is exists or not?
Possible Duplicate:
Is there an “exists” function for jQuery
<div class="XXX">
<div class="created">
</div>
</div>
div class="created"
automatically generated by JavaScript using append function jQuery for some validation i need to check whether div is generated or not how can i do this.using jQuery.
something like $('.xxx').html()==' '
Try this like following:
$('div.XXX div.created').length
if the div
is not create then $('div.XXX div.created').length
will return 0.
if( $('div.XXX div.created').length > 0 ){
// do something
}
In jQuery, it has method .size()
and implement like $('div.XXX div.created').size()
, but .length
is more reliable.
你可以使用jQuery length
属性返回所选元素的数量:
if ($('.XXX div.created').length > 0) {
}
链接地址: http://www.djcxy.com/p/14684.html
上一篇: 为什么如果总是返回true?
下一篇: 如何检查div是否存在?