
Untitled
By: a guest on
Aug 11th, 2012 | syntax:
None | size: 1.12 KB | hits: 7 | expires: Never
appendChild method is not defined when using with a div element
<!doctype html>
<html>
<head>
</head>
<body>
<p>This is paragraph 1.</p>
<p>This is paragraph 2.</p>
<p>This is paragraph 3.</p>
<p>This is paragraph 4.</p>
<div>
<p id="foo">This is paragraph 5.</p>
</div>
<script type="text/javascript" src="script.js"></script>
</body>
</html>
(function(){
var divElement = document.getElementsByTagName("div");
el = document.createElement("p");
content = document.createTextNode("This is text");
el.appendChild(content);
document.divElement.appendChild(el);
}());
var divElement = document.getElementsByTagName("div")[0];
document.divElement.appendChild(el);
divElement.appendChild(el);
(function() {
var divElements = document.getElementsByTagName("div");
var el = document.createElement("p");
var content = document.createTextNode("This is text");
el.appendChild(content);
for (var i = 0; i < divElements.length; i++) {
divElements[i].appendChild(el);
}
}());