18

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()==' '

0

2 Answers 2

11

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.

5

you can use jQuery length property which returns the number of selected elements:

if ($('.XXX div.created').length > 0) {

}

Not the answer you're looking for? Browse other questions tagged or ask your own question.