I'm trying to learn how to create a as a child of another using JavaScript. My example below is functioning fine in Chrome and IE, but in Firefox I get an error that says "viewport is not defined" for the viewport.appendChild line in the JS.
The html looks like this:
<body>
<div id="viewport"></div>
</body>
and the JS looks like this:
function createDiv() {
var divTag = document.createElement("div");
divTag.class开发者_开发知识库Name ="tile";
viewport.appendChild(divTag);
}
That's because you haven't defined viewport
. Somewhere in the function above the appendChild
line, add this:
var viewport=document.getElementById('viewport');
精彩评论