javascript - getElementById trouble -


html: [...]<div id="test" name="testvalue"></div>[...]

js[...]alert(document.getelementbyid("test").name);[...]

why 'undefined' instead of 'testvalue'?

because name not valid attribute <div> element. such, doesn't map .name property.

you using getattribute() method though:

alert(document.getelementbyid("test").getattribute("name")); 

example: http://jsfiddle.net/bcyxl/


Comments

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

java - Output of Eclipse is rubbish -

jquery - Confused with JSON data and normal data in Django ajax request -