Check for document ID?

Check for document ID?

Post by michae » Thu, 24 Jun 2004 07:10:52

Is there a way for Javascript to check if a document CSS id exist anywhere
on a page, for example, if "bla" exists?

<a href="asf" id="bla">

Check for document ID?

Post by CryingClin » Thu, 24 Jun 2004 13:02:33

var obj=document.getElementById('bla');
if (typeof(obj)=='undefined' ) alert('The object does not exist!'); // or

"michael" < XXXX@XXXXX.COM > ????


Check for document ID?

Post by Richard Co » Thu, 24 Jun 2004 19:31:45

The W3C Core DOM - getElementById - method is specified as returning -
null - when it cannot locate an element with a corresponding ID
attribute in the DOM. The - typeof - operator returns the string
"object" when its operand is - null - so neither of these tests will
work. A type-converting test would be more effective in this situation.

Please do not top-post in comp.lang.javascirpt.