Working on an idea for a simple HTMLElement wrapper I stumbled over for Internet Explorer and:
For the HTMLElement given with the ID in the DOM tree, it is possible to div use the ID as the variable name. So for a div
& lt; Div id = "example" & gt; Some text & lt; / Div & gt; In and Chrome you can:
Warning (example.innerHTML); // = & gt; 'Some text' or
warning (window ['example']. InnerHTML); // = & gt; 'Some text' So, does it mean every element in the DOM tree is converted to a variable in the global namespace? And does it also mean that they can be used as a replacement for the getElementById method in these browsers?
What is considered is that the "named elements" to the document This is a very bad idea, because it allows the names of elements to fight with the real properties of document . IE has doubled the status even more <> the window object that you now have any member of the document or window You should want to avoid the names of your elements (or any other library code in your project) after using it. It also means that these elements are visible in the form of a global variable. Fortunately, in this case, any real global var or function shuts announcements in your code, so you do not have to worry about giving a lot of name here. , But if you try to assign a global variable with a collision and you forget to declare it as var , you will get an error in IE because it specifies the value for the element A Tries. It is generally considered to be a poor practice to leave var , as well as to rely on named elements on windows or globals Paste on document. GetElementById , which is more widely supported and less ambiguous If you do not like typing, you can write a trivial cover with a short name. Either way, there is no point in using the ID-to-element lookup cache, because browsers usually optimize getElementById calls, to use a quick lookup; Problems occur when you change the element to id or add to the document. Opera has copied IE, then joined WebKit, and now by putting the designated elements on both predefined standard practice documents properties, and already on the Internet - By typing the window , HTML5, whose viewpoint is documenting and standardizing horrible practices, we make them a part of the web forever by browser authors. So Firefox 4 will also support it. Elements are named ??? Anything with id , and being used to identify anything with the name ???? Objectives: That is, the form, picture, anchor and some other, but other unrelated examples of the name attribute, such as control-names in input input fields, & lt; Parameter name in param & gt; or Metadata type & lt; Meta & gt; in a ???? Identifying names s are those which should be avoided in favor of id .
Comments
Post a Comment