javascript - Preferences given for html control attributes for attributes with the same value -


what preferences given html control attributes if 2 attributes have same value id="xyz" name="xyz" ?

my piece of code shown :

<iframe scrolling="no" width="100%" name="topframe" id="topframe" frameborder="0" height="100%" runat="server"></iframe> 

i'm trying access iframe via attribute. when call iframe javascript:parent.frames['topframe'] value 1 of them preferred

the first thing note window.frames just alias window:

the window, frames, , self idl attributes must return window object's browsing context's windowproxy object.

the relevant part of specification here:

the supported property names @ moment consist of following, in tree order, ignoring later duplicates:

  • the browsing context name of child browsing context of active document name not empty string,
  • the value of name content attribute a, applet, area, embed, form, frameset, img, , object elements in active document have non-empty name content attribute, and
  • the value of id content attribute of html element in active document non-empty id content attribute.

so doesn't matter 1 "preferred".

if id , name of element same, 1 used determine name , other ignored. if id="a" used , name="a" ignored, a. if other way around, still a.

if id , name of element different, can both used reference it.

if 2 different elements share value between name , id attributes, whichever element comes first take name. particular attribute used doesn't matter.


use of id , name attributes directly not recommended. can clash existing properties of window object. better use getelementbyid or queryselector can explicitly looking element in dom.


Comments

Popular posts from this blog

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -