document.getElementById in IE7
2009-07-16 22:00:13
Opened: 717 times
Given the following code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>IE7 getElementById() test</title>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<meta http-equiv="Content-Style-Type" content="text/css" />
<meta name="description" content="Internet Explorer 7 getElementById() test" />
</head>
<body>
<form action="index.php" method="post">
<div>
<label for="description">Description: </label>
<textarea rows="10" cols="82" name="foo" id="description">Write some description here...</textarea>
<button type="submit">Save</button>
</div>
</form>
<script type="text/javascript">
<!--
var obj = document.getElementById('description');
document.write('getElementById() returned a ' + obj.tagName + ' node');
//-->
</script>
</body>
</html>Can you guess what the output will be? Yes, for most of the cases it will be "TEXTAREA". But not for IE7 (and older)! According to the docs it will be "META". If you want to be Internet Explorer 7 compatible, you should never-ever call any object you want to access from JavaScript "description".
Tags: msie javascript getelementbyid
