0
点赞
收藏
分享

微信扫一扫

在指定元素的末尾插入 HTML 字符串

非常帅气的昵称吧 2022-07-27 阅读 113

使用位置为 ​​afterend​​​ 的 ​​Element.insertAdjacentHTML()​​​ 解析 ​​htmlString​​​ 并将其插入 ​​el​​ 末尾。

const insertAfter = (el, htmlString) =>
el.insertAdjacentHTML('afterend', htmlString)

insertAfter(document.getElementById('myId'), '<p>after</p>')
// <div id="myId">...</div> <p>after</p>

举报

相关推荐

0 条评论