Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
193
rated 0 times [  195] [ 2]  / answers: 1 / hits: 8530  / 10 Years ago, wed, april 16, 2014, 12:00:00

Below is some sample code.



<body>
<div id=wrapper class=access>
<form id=test>
<input id=password></input>
<input type=submit></input>
</form>
</div>
<script>
console.log(password);
alert(wrapper.className);
</script>
</body>


The console log returns the DOM element with id password. The alert is alert.



It works in normal code as well, e.g. var x = wrapper.className;



Surely this is not right? What is the point of document.getElementById, $('#password') or goog.dom.getElement if it just works like this? Are these functions just for legacy now?



It works in Firefox, Chrome and Safari, incidentally.


More From » dom

 Answers
5

This answer should give you a lot to go on:



https://stackoverflow.com/a/6381766/944006



You shouldn't use these variables, and you DEFINITELY don't want to depend on them working correctly across browsers.


[#45955] Wednesday, April 16, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
byron

Total Points: 616
Total Questions: 101
Total Answers: 91

Location: Reunion
Member since Wed, Apr 14, 2021
3 Years ago
;