Walgreens Interview Question

Why does Javascript have two ways of getting HTML elements for example one way is to use getElementByID and another is document.[element].[value]

Interview Answer

Anonymous

Apr 14, 2012

getElementByID is just a DOM method that provides a shortcut to get to the element its ID attribut. The same element is still located in the DOM tree and can be accessed if we know his full path. There are more than 2 ways: by class name by tag name etc...