1 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Strict//EN"> |
---|
2 | <html> |
---|
3 | <head> |
---|
4 | <meta content="text/html; charset=UTF-8" http-equiv="content-type"> |
---|
5 | <title>test firstChild ≠ childNodes[0]</title> |
---|
6 | <script> |
---|
7 | function checkFirstChildAttribute() { |
---|
8 | var point = document.getElementById("p"); |
---|
9 | var parent = point.parentNode; |
---|
10 | var firstChild = parent.firstChild; |
---|
11 | var child0 = parent.childNodes[0]; |
---|
12 | if (firstChild == child0) { |
---|
13 | alert("Equal!"); |
---|
14 | } else { |
---|
15 | alert("Not equal!\n\nparent=" + parent.outerHTML + "\n\nfirstChild=" + firstChild + "; child[0]=" + child0.outerHTML); |
---|
16 | } |
---|
17 | } |
---|
18 | </script> |
---|
19 | </head> |
---|
20 | <body> |
---|
21 | <p><span><p id="p">aaa</p></span><p>bbb</p> |
---|
22 | <a href="#" onclick="checkFirstChildAttribute()">test firstChild ≠ childNodes[0]</a><br> |
---|
23 | <br> |
---|
24 | </body> |
---|
25 | </html> |
---|