DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

No More NULL Returned By GetElementById

  • submit to reddit
        // 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; }