Search code examples
javascripthtmlcsstampermonkey

Element won't appendChild


So I have a tampermonkey script that creates some elements and appends them.

So my first element with the classname: ControllerBG appends to a element with a 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"?

Here's my JSFIDDLE with the JavaScript.

https://jsfiddle.net/60nzjxf3/

I've even tried:

ControllerBG.innerHTML = TopContainer

Solution

  • You are appending the TopContainer into several other elements. Only the last one (AboutContent) will actually have it, and you're not appending that element into the document.

    ControllerBG.innerHTML = TopContainer wouldn't work because TopContainer is an element, not an HTML string.