标签:span ast innerhtml last div style after element document
const app = document.getElementById(‘app‘); app.innerHTML = ` <h1>JavaScript DOM</h1> <ul> <li>1</li> </ul> `; const ul = app.querySelector(‘ul‘); ul.insertAdjacentHTML(‘beforebegin‘, ‘<p>Before</p>‘); // <p>Before</p><ul><li>1</li></ul> ul.insertAdjacentHTML(‘afterbegin‘, ‘<li>First</li>‘); // <li>First</li><ul><li>1</li></ul> ul.insertAdjacentHTML(‘beforeend‘, ‘<li>Last</li>‘); // <ul><li>1</li><li>Last</li></ul> ul.insertAdjacentHTML(‘afterend‘, ‘<p>After</p>‘); // <ul><li>1</li></ul><p>After</p>
Using ‘
insertAdjacentHTML
‘ is faster than innerHTML.
[HTML 5] Inserting DOM as String template insertAdjacentHTML
标签:span ast innerhtml last div style after element document
原文地址:https://www.cnblogs.com/Answer1215/p/12542029.html