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

asked Jul 21, 2012 at 6:54
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.

answered Jul 21, 2012 at 6:56
Sign up to request clarification or add additional context in comments.

Comments

5

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

if ($('.XXX div.created').length > 0) {
}
answered Jul 21, 2012 at 6:56

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.