JS - add element after element

0 votes
193 views
added Jul 3, 2019 in Javascript by LC Marshal Captain (25,790 points)
var appendMe=1;
function appendFunction(){
    var parentElement = document.getElementById('main-content');      
    var node = document.createElement("DIV");
    var textnode = document.createTextNode("This was added dinamically");
    node.appendChild(textnode);     
    node.id = 'new-div_' + appendMe;
    var child = parentElement.children[2];
    parentElement.insertBefore(node, child);
    appendMe++;

}

 

lazacode.org - Malaysia's programming knowledge sharing platform, where everyone can share their finding as reference to others.
...