简体   繁体   English

元素不会 appendChild

[英]Element won't appendChild

So I have a tampermonkey script that creates some elements and appends them.所以我有一个 tampermonkey 脚本,它创建一些元素并附加它们。

So my first element with the classname: ControllerBG appends to a element with a id "motd".因此,我的第一个类名元素:ControllerBG 附加到 ID 为“motd”的元素。

When my second element tries to append I see nothing or get no errors in the console.当我的第二个元素尝试附加时,我在控制台中什么也看不到或没有错误。

Example.例子。

ControllerBG.appendChild(TopContainer);

It only appends the first var/element and it looks like this它只附加第一个变量/元素,它看起来像这样

<div class="ControllerBG" item-controlv1=""></div>

Why won't the other elements append to that element, also known as the variable "TopContainer"?为什么其他元素不附加到该元素(也称为变量“TopContainer”)?

Here's my JSFIDDLE with the JavaScript.这是我的 JSFIDDLE 和 JavaScript。

https://jsfiddle.net/60nzjxf3/ https://jsfiddle.net/60nzjxf3/

I've even tried:我什至尝试过:

ControllerBG.innerHTML = TopContainer

You are appending the TopContainer into several other elements.您正在将 TopContainer 附加到其他几个元素中。 Only the last one (AboutContent) will actually have it, and you're not appending that element into the document.只有最后一个 (AboutContent) 才会真正拥有它,并且您没有将该元素附加到文档中。

ControllerBG.innerHTML = TopContainer wouldn't work because TopContainer is an element, not an HTML string. ControllerBG.innerHTML = TopContainer不起作用,因为 TopContainer 是一个元素,而不是 HTML 字符串。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM