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()==' '
$(document). ready(function() { if ($('#DivID'). length){ alert('Found with Length'); } if ($('#DivID'). length > 0 ) { alert('Found with Length bigger then Zero'); } if ($('#DivID') !=
There are two ways to check whether an element in the HTML document exists or not using jQuery. Approach 1: Using the length property in jQuery. If the element exists, then the length property will return the total count of the matched elements with the specified selector.
In jQuery, you can use the . length property to check if an element exists. if the element exists, the length property will return the total number of the matched elements. To check if an element which has an id of “div1” exists.
Answer: Use the jQuery . length Property You can use the jQuery . length property to determine whether an element exists or not in case if you want to fire some event only if a particular element exists in DOM. Here's an example that displays an alert on button click if the specified element exists.
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.
you can use jQuery length
property which returns the number of selected elements:
if ($('.XXX div.created').length > 0) {
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With