Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #36000 > unrolled thread
| Started by | Mickey Finn <mfinney@gmail.com> |
|---|---|
| First post | 2019-02-08 22:19 -0200 |
| Last post | 2019-02-08 22:19 -0200 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.javascript
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: Element ids as global names Mickey Finn <mfinney@gmail.com> - 2019-02-08 22:19 -0200
| From | Mickey Finn <mfinney@gmail.com> |
|---|---|
| Date | 2019-02-08 22:19 -0200 |
| Subject | Re: Element ids as global names |
| Message-ID | <q3l69l$f97$1@gioia.aioe.org> |
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 top | Article view | comp.lang.javascript
csiph-web