Is document an alias of Sys.UI.DomElement in JavaScript?
I have come across this example in msdn.
$addHandler(Sys.UI.DomElement.getElementById("Button1"), "click", toggleCssClassMethod);
I used to see only document.getElementById(id). So raised this question.Itmight be sound bad. But I am just kid in JS world.
No, the two are not the same. I think your confusion is probably coming from the common misconception that
getElementByIdis a function only belonging todocument. In fact, you can usegetElementByIdon other DOM elements. Something like this works just fine:http://jsfiddle.net/CNc2s/
Notice that the 2nd call of
getElementByIdis being called on the DOM element returned by the first call. This will find an element with an id oftest2within an element with andidof test.The reason you don’t often see things like this is that
ids must be unique within a document. So calling it on the document will get the same element as calling it on a containing element.