In JavaScript, the standard ID selector invocation syntax is:
document.getElementById (' myID '). Style.width = pc + "%";
However, today, it is found that directly with the ID name call unexpectedly can also run correctly:
myid.style.width = pc+ "%";
Finally looked for Niang asked.
See MRCXT's blog has this problem, the answer to the question is:
It was originally IE
inside, and it seemed to support it later firefox
chrome
. Not recommended, this is not the standard inside, not necessarily support in the future. And the code is easy to write confusing, belong to the multiNavItem1
global scope, and you can assign to him, after the assignment is the new value, the value is not assigned to that element, when some of the id
value is not, then some is this DOM
object, some not, especially easy to confuse.
Looked for again, did not find the official answer, but should be similar to this.
So, the final conclusion is: can use, but is not the standard recommended, and error-prone, so it is not recommended to use!
Insight learn shallow, welcome to shoot Bricks!
Daily Learning notes----JS can be called directly with the ID name of the problem?