17

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

Community
  • 1
  • 1
Anudeep GI
  • 913
  • 3
  • 14
  • 45

2 Answers2

10

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.

thecodeparadox
  • 84,459
  • 21
  • 136
  • 161
5

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

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

}
Ram
  • 140,563
  • 16
  • 160
  • 190