Thank Oleg - worked a charm. I had no idea it would be as simple as that.
Still need to get used to the new-ish JavaScript methods.
Cheers!!
Sam K
> try :
var obj = document.getElementById(element);
if (obj)
' then exist
else
' not exist
Oleg.
-----Original Message-----
From: Sam Kirkpatrick [mailto:sam@s...]
Sent: June 06, 2002 9:04 AM
To: javascript
Subject: [javascript] Detecting existence of objects
Hi all,
I am currently trying to implement an expandable tree using DHTML. This
tree appears in numerous places throughout the application. Each time a
page which contains the tree is unloaded, a cookie is set which records
which nodes of the tree were expanded, so that when the page is reloaded,
it automatically expands those nodes again.
However, if the number of nodes on the page happens to decrease,
JavaScript errors appear as it potentially tries to expand nodes which
don't exist. Each node is a <span&tg; tag.
My question - how do I adequately check that a node exists before
attempting to expand it? I have tried all the "if ( element )" and "if (
element + "" = "undefined" )" etc, etc - all to no avail.
Many thanks in advance.
Sam K
---
Improve your web design skills with these new books from Glasshaus.
Usable Web Menus
http://www.amazon.com/exec/obidos/ASIN/1904151027/ref=nosim/theprogramme
r-20
Constructing Accessible Web Sites
http://www.amazon.com/exec/obidos/ASIN/1904151000/ref=nosim/theprogramme
r-20
Practical JavaScript for the Usable Web
http://www.amazon.com/exec/obidos/ASIN/1904151051/ref=nosim/theprogramme
r-20
---
Change your mail options at http://p2p.wrox.com/manager.asp or
to unsubscribe send a blank email to