How to dynamically position a div with content inside another created dynamically?

1

On my site, I create a div dynamically after the second paragraph (forum).

I would like to place a banner already loaded within this div .

I tried several ways, give apendchild , but it will not.

Here is the URL of the site to understand:

Below the code I'm using to create div :

var meupost = document.getElementsByClassName("post entry-content ")[0];
var meudiv = meupost.getElementsByTagName("p")[1];
var meubanner = document.createElement("div");
meubanner.id = "banner300x250-1-auto";
meubanner.setAttribute('class','ipsBox_container');
meubanner.style.height = "250px";
meubanner.style.width = "300px";
//meubanner.style.position = "relative";
meubanner.style.float= "right";
meupost.insertBefore(meubanner, meudiv);
    
asked by anonymous 10.10.2014 / 00:55

1 answer

1

Man, at runtime, it will not add up because at the time it is reading the DOM, it will not find the element you are identifying to give the append. For this to work, this div should already be in the DOM at the time javascript starts executing. Dai dynamically fill in the div, and add a class that defines the div's styles.

    
14.10.2014 / 16:55