[Javascript] javascript and id's
Anthony Ettinger
apwebdesign at yahoo.com
Tue Oct 4 13:20:17 CDT 2005
--- Paul Novitski <paul at novitskisoftware.com> wrote:
> At 10:36 AM 10/4/2005, you wrote:
> >I've shortened the function:
> >
> >function changeAttrib(id, attrib, newValue)
> >{
> >
> document.getElementById(id).setAttribute(attrib,
> >newValue);
> >}
>
> I would argue for a safer coding practice:
>
> var oEl = document.getElementById(id);
> if (oEl) oEl.setAttribute(attrib,
> newValue);
>
> ...in order to avoid a javascript error message if
> the expected
> element doesn't exist on the page.
>
Great. So you recommend testing for getElementById
first, good idea.
Would you bother with an else in that statement? Or
simply break it. I personally don't care to support
older versions of IE and NS. Accessible means screen
readers, mobile devices, etc. ANY javascript would
break on those.
Anthony Ettinger
ph: (408) 656-2473
blog: http://www.chovy.com
__________________________________
Yahoo! Mail - PC Magazine Editors' Choice 2005
http://mail.yahoo.com
More information about the Javascript
mailing list