我有一些使用 jQuery replaceWith
函数的代码,但似乎 replaceWith
摆脱了 div I 上的伪元素 :after
正在调用 replaceWith
on。
是否有一个类似的函数,其作用与 replaceWith
完全相同,但不会破坏我的 :after
伪元素?
这是我的代码:
$("#someDiv").replaceWith("some text here");
这是 jQuery 的预期行为还是错误?
最佳答案
.replaceWith
删除调用它的元素。如果没有元素,:after
伪元素就无法存在。
您可以使用 $("#someDiv").html("some text here");
来替换 div content,而不是 div 本身
关于javascript - jQuery replaceWith 删除我的 :after pseudoelement,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25573826/