
February 22nd, 2007, 12:28 PM
|
 |
Contributing User
|
|
Join Date: Aug 2006
Location: Estonia
|
|
Quote: | Originally Posted by Damien-uk
I'm doing some fairly basic client-side JS and wondered if there's a simple way to do something like:
Code:
if(getElementByID("someId"))
//do something
|
The code you provided is the most elegant way of checking for element with specified ID.
That way you can see that code depends on a presence of a certain ID in the document, while try ... catch will catch all errors, even those that are not related to missing IDs.
I would recommend sticking with your code, it's elegant and good coding style.
|