Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #36000
| From | Mickey Finn <mfinney@gmail.com> |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Re: Element ids as global names |
| Date | 2019-02-08 22:19 -0200 |
| Organization | Aioe.org NNTP Server |
| Message-ID | <q3l69l$f97$1@gioia.aioe.org> (permalink) |
| References | <element-ids-20190205124317@ram.dialup.fu-berlin.de> |
Stefan Ram wrote: > When one has an element > > <em id=a>abc</em> > > and then evaluates »a« in JavaScript, that element is yielded. It may happen with HTML elements having a name attribute too. This feature is called "Named access on the Window object" and is standardised in HTML5 [1][2], although it is non-normative. > > Which of the following lines is the best expression for this element > (from the point of view of programming style and maintainability)? > > this.document.getElementById( 'a' ) > window.document.getElementById( 'a' ) > document.getElementById( 'a' ) > a > (or something else, I have not listed above?) Use document.getElementById() or document.querySelector(). Why complicate things? > > Is the feature to make the HTML ids become global names in > JavaScript deprecated (obsolete) or expected to become > deprecated (obsolencent)? > > See the answer in the links below. [1] <https://html.spec.whatwg.org/multipage/window-object.html#named-access-on-the-window-object> [2] <https://www.w3.org/TR/2011/WD-html5-20110525/browsers.html>
Back to comp.lang.javascript | Previous | Next | Find similar | Unroll thread
Re: Element ids as global names Mickey Finn <mfinney@gmail.com> - 2019-02-08 22:19 -0200
csiph-web