使用appendchild将div添加到另一个div

时间:2016-10-04 19:29:54

标签: javascript append appendchild

我正在改变现有的wordpress主题。 我试图将页脚中的div移动到正文。 这是我用appendchild写的,但似乎没有用。

function myFunction() {
    document.getElementsByClassName("td-post-author-name")[0].setAttribute("id", "block-under-title");
    document.getElementsByClassName("td-post-small-box")[0].setAttribute("id", "real-author-name");
    var changeName = document.getElementsById("real-author-name");
    document.getElementById("block-under-title").appendChild(changeName);
}


window.onload = function() {
  myFunction();

};

1 个答案:

答案 0 :(得分:2)

你有一个拼写错误,没有方法getElementsById,把它改成getElementById它会正常工作(第4行)

相关问题