<!DOCTYPE html>
<html>
<head>
<title>Test</title>
</head>
<script type="text/javascript">
function fire() {
console.log(document.body.children.length);
console.log(document.body.children[0].children.length);
}
</script>
<body onload="fire()">
<div>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer pharetra ipsum erat. Aenean convallis laoreet massa, et gravida purus faucibus ac. <a id="test"/>Vestibulum libero justo.</p>
</div>
</body>
</html>
When you open the console, you'll see that the <a>
is a children
of <body>
, <div>
and <p>
. WTF??なぜですか<a id="test"/> breaks out of the DOM chain?
If <a>
is closed with a "proper" closing tag the issue disappears and its only child of <p>
.
Can someone explain this to me?
PS: Tested on Chrome stable.
「」タグを自己クローズできないためです。 HTMLは無効であり、予期せず動作する可能性があります。 – JJJ
ここで説明します:http://stackoverflow.com/questions/97522/what-are-all-the-valid-self-closing-tags-in-xhtml-as-implemented-by-the-major-b –
Content-Type "application/xhtml + xml"を使用して作業していますか? –