[Javascript] Check if an element exists in the DOM

Simone Fumagalli simone at tomato.it
Wed Oct 18 07:49:59 CDT 2006


Hello.

How do I check if an element with id="XYZ" is present in my page/DOM ?

I've tried with:

if ($('XYZ') == undefined) {
  // Do something
} else {
  // Do something else
}

but, of course, javascript give me an error of undefined object.

Ideas ?

Simone




More information about the Javascript mailing list