✅javascript 语法:附加子节点

received: function(data) {

 $("#notifications").prepend(data.html);
}

如何用原生js写出jquery的功能:

先创建<div>节点,然后附加到需求元素的内部,然后改变这个<div>的innerHTML。

var p = document.createElement('div')

document.getElementById("notifications").appendChild(p)

document.getElementById("notifications").lastChild.innerHTML = data.html

原文地址:https://www.cnblogs.com/chentianwei/p/9307281.html