我有如下意见之间的HTML特殊内容移动HTML代码注释之间(含评论)
<p>Regular text</p>
<p>Regular text</p>
<!--Special Content-->
<p>Special Content 1</p>
<p>Special Content 2</p>
<!--/Special Content-->
<p>Regular text</p>
<p>Regular text</p>
<p id="reference">Place special content with comments below this <p> element</p>
我要评论<!--Special Content-->
和<!--/Special Content-->
包括评论本身之间的HTML内容包装成一个<div>
和将它移动到<p id="reference">
元素下方。
我无法访问实际的HTML模板,所以需要通过JavaScript或JQuery来完成。
我一直无法找到一种方法来包装目前的评论内容。
最终结果应该是:
<p>Regular text</p>
<p>Regular text</p>
<p>Regular text</p>
<p>Regular text</p>
<p id="reference">Place special content with comments below this <p> element</p>
<div id="wrapper">
<!--Special Content-->
<p>Special Content 1</p>
<p>Special Content 2</p>
<!--/Special Content-->
</div>
我很欣赏你的想法。
你尝试过这么远吗?我不太确定jQuery是“定位”评论节点的最佳选择 - 这可能在vanilla JS中更简单。 – CBroe
@Rory McCrossan:它的信息和跟踪。其他内容会动态添加到“特殊内容”区域,如果没有其评论的话,移动它会给其他人使用“特殊内容”引用其他动作/事件造成问题 –
@CBroe:纯JS也很好。我很欣赏你的方向。 –