Wrox Home  
Search P2P Archive for: Go

  Return to Index  

javascript thread: Detecting existence of objects


Message #1 by "Sam Kirkpatrick" <sam@s...> on Thu, 6 Jun 2002 13:04:28
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 &lt;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 

  Return to Index