0

I have this code which creates an element but the problem i am facing is it appends it at the very bottom of the page, in order for this to work i need it to be positioned in a certain place in the DOM how can i do this ?

var x  = document.getElementById('options_10528_1');
var pos = document.getElementById('options-10528-list');
x.onclick = function(){
var elem = document.createElement('div');
elem.setAttribute("class","uk-warning");
elem.innerHTML = "Unfortunately, we cannot supply this medicine. Please  consult your GP.";
document.body.appendChild(elem);
}

2 Answers2

0
afterWhichNode.parentNode.insertBefore(newNode, afterWhichNode.nextSibling);

This code will insert a node after the afterwichNode, thats using vanilla javascript, if you are using jquery, just use .after()

0

Currently you are appending the element in the body tag, it will always goes at bottom. So if you want to append the element in a specific position, you have to append it in that container. let say you want to append it in "pos", you can do this:

pos.appendChild(elem);
BIlal Khan
  • 453
  • 3
  • 16