开发者

appendChild doesn't seem to be playing nice in FireFox

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');
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜