⬆️ 需要: tag()
// ⭐️ node.appendTag() Node.prototype.appendTag = function(name, { textContent, attributes = {} }={}){ let elem = tag(name, {textContent, attributes}); this.appendChild(elem); return elem; };
const header = document.body.appendTag('header'); const h1 = header.appendTag('h1', {textContent: 'Hello DOM'});
helper functions
MDN ⟩ Node ⟩ .appendChild()
Last updated 1 year ago