[Javascript] Check if ID exist

Matt Warden mwarden at gmail.com
Fri Aug 18 13:47:08 CDT 2006


On 8/18/06, Peter Lauri <lists at dwsasia.com> wrote:
> How do I check if an element with a specific ID exists?
>
> Before I call a function I need to check if some elements are in the
> document already.

You can simply check if document.getElementById('id') returns a non-false value.

I suspect you want something to happen when the element *is*
available. Check out YUI's utility for that:

http://developer.yahoo.com/yui/event/#deferral

-- 
Matt Warden
Cleveland, OH, USA
http://mattwarden.com


This email proudly and graciously contributes to entropy.



More information about the Javascript mailing list