Over a million developers have joined DZone.

No More NULL Returned By GetElementById

DZone's Guide to

No More NULL Returned By GetElementById

Free Resource
// If you search for an ID that doesn't exist, getElementById(id) will return NULL, filling your error console with some stuff in it.

Now, everything is clear. No more error, no more NULL return. getElementById will now being silent for ever.

function GetID(id) { return (document.getElementById(id))?document.getElementById(id):false; }

Opinions expressed by DZone contributors are their own.


Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.


{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}