我有这个代码创建了一个元素,但是我面对的问题是它将它追加到页面的最底部,为了这个工作我需要它被定位在DOM中的某个地方,我该怎么做?将元素放置在DOM中的某个地方JavaScript
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);
}
你必须知道容器中添加元素.. – Rayon
我知道它包含在这样做,我只是将其追加到你们? –
要定位添加元素作为孩子检查此: http://stackoverflow.com/questions/5882768/how-to-append-a-childnode-to-a-specific-position –