Problem: During the development process, it is used to loop into the table and then loop into the td. There is no problem in other browsers, but errors are reported in IE9 and the following versions:
Got the answer on Google: Because I didn't know the error before, I couldn't find a solution on Baidu. Later, I searched it with Google. Some foreigners also encountered this problem and pointed out the problem: http://www.aachin.info/techen/error-on-ie-9-script600-invalid-target-element-for-this-operation/?amp;utm_source=rss&utm_medium=rss&utm_campaign=error-on-ie-9-script600-invalid-target-element-for-this-operation demo code:
The code copy is as follows:
<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<title>Default title</title>
</head>
<body>
<table id="mytable" cellpadding="1" cellpacing="0">
<tr>
<td>222</td>
</tr>
</table>
<script type="text/javascript">
var mytable = document.getElementById('mytable');
var tr = mytable.getElementsByTagName('tr')[0];
var td = mytable.getElementsByTagName('td')[0];
//Read innerHTML (no errors are reported in any version of IE, IE6 has not been tested)
alert(mytable.innerHTML);
alert(tr.innerHTML);
alert(td.innerHTML);
//Write to innerHTML
// mytable.innerHTML = '<tr><td>11111</td></tr>'; //IE9 and the following error
// tr.innerHTML = '<td>11111</td>'; //IE9 and the following errors
// td.innerHTML = '11111'; //All versions do not report errors (IE6 is not tested)
//Solution, use the original operation method or table operation method of DOM
// var btnRow = mytable.insertRow();
// var cell = btnRow.insertCell(btnRow.getElementsByTagName('td').length);
// cell.innerHTML = "some html text";
</script>
</body>
</html>
Conclusion: The innerHTML attributes of tables and tr are read-only in IE9 and below. You can use it to read the values in tables or tr, but they cannot be written. If you write, it will report an error. In addition, the innerHTML of td is readable and writable in IE9 and below. Solution: See the demo code for the original DOM operation method or table operation method.