开发者

appendChild doesn't seem to be playing nice in FireFox

开发者 https://www.devze.com 2023-03-12 16:09 出处:网络
I\'m trying to learn how to create aas a child of anotherusing 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

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

精彩评论

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