tags:

views:

40

answers:

2

Using jQuery, how can I validate if a div exists in body of a HTML page or not?

+3  A: 

For the presence of any div:

if ($("div").length > 0) {
  // theres a div
}

Or a particular element with an ID:

if ($("#id").length > 0) {
  // it exists
}
cletus
A: 
var divExists = !!$('div').length;
David