Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Missing DOM element

I am using Chrome 30.0.1599.101 and have issue with name element: it has no properties.

<html>
<body>
<form>
    <input name="name" id="name" type="text">*<br>
    <input name="pass" id="pass" type="text">*<br>
</form>

<script>

var name = document.getElementById("name");
var pass = document.getElementById("pass");

console.log(name); // no properties
console.log(pass); // everything ok

</script>
</body>
</html>

Why has name element has no properties? It's not only the console issue - the properties are not accessible in the code. However, everything works fine in Firefox browser. Even in the fiddle (by Gurpreet Singh) with the very same code in the same browser everything works. I tried <!DOCTYPE html5> as Uooo suggests, tried to reset the browser, but still no luck on localhost.

Here is a screenshot:

error screenshot

If I change the name name to something else, the properties are visible.

like image 639
Jan Turoň Avatar asked Oct 20 '22 22:10

Jan Turoň


1 Answers

name is already a global property (a property of window), and not only that, it is kinda typed (String). var name = ... is essentially the same as as saying window.name = .... Use another variable name that is actually not taken yet and you should be fine.

like image 102
nmaier Avatar answered Oct 27 '22 20:10

nmaier