From: FAQ server on 9 Aug 2010 19:00 ----------------------------------------------------------------------- FAQ Topic - Why doesn't the global variable "divId" always refer to the element with id="divId"? ----------------------------------------------------------------------- Microsoft introduced a shortcut that can be used to reference elements which include an `id` attribute where the `id` becomes a globally-accessible property. Some browsers reproduce this behavior. Some, most notably Gecko-based browsers (Netscape and Mozilla), do so only in "quirks" mode. The best approach is the `document.getElementById` method, which is part of the W3C DOM standard and implemented in modern browsers (including IE from version 5.0). So an element with `id="foo"` can be referenced with:- var el = document.getElementById("foo"); Note: make sure not to use the same `id` twice in the same document and do not give an element a `name` that matches an `id` of another in the same document or it will trigger bugs in MSIE <= 7 with `document.getElementsByName` and `document.getElementById`. <URL: https://developer.mozilla.org/en/Using_Web_Standards_in_your_Web_Pages/Using_the_W3C_DOM#Accessing_Elements_with_the_W3C_DOM > <URL: http://jibbering.com/faq/faq_notes/faq_notes.html#FAQN4_41> The complete comp.lang.javascript FAQ is at http://jibbering.com/faq/ -- The sendings of these daily posts are proficiently hosted by http://www.pair.com.
|
Pages: 1 Prev: Function Priority ?? Next: AJAX function doesn't return responseText in the right place |