Skip to content Skip to sidebar Skip to footer

Do I Really Need To Call Getelementbyid()?

Possible Duplicate: IE/Chrome: are DOM tree elements global variables here? I just stumbled upon an unexpected but useful behavior in the browser: It creates a variable for ever

Solution 1:

When creating elements with IDs, the "window" object receives the specific attributes, that's why you can use variables directly, this behavior is deprecated and usually is wrote like this: window.ohlala.innerHTML = "...", this behavior is conserved by the browsers for compatibility with some older code on websites, but it is not recommended to use it in modern websites, always use .getElementById() method, this method is part of a W3C Standard, and you can use it in all modern browsers, in some very old browser versions and < IE7 it will not work. Learn more about DOM (Document Object Model) here: https://developer.mozilla.org/en-US/docs/DOM


Post a Comment for "Do I Really Need To Call Getelementbyid()?"