有没有办法使用jQuery 选择/操作CSS伪元素,如::before和::after(以及带有一个分号的旧版本)?
例如,我的样式表具有以下规则:
.span::after{ content:'foo' }
Run Code Online (Sandbox Code Playgroud)
如何使用jQuery将'foo'更改为'bar'?
我可以让CSS使用生成的内容显示元素的ID,如下所示:
<style>
h2:hover:after {
color: grey;
content: "#" attr(id);
float: right;
font-size: smaller;
font-weight: normal;
}
</style>
<h2 id="my-id">My ID</h2>
<p>Pellentesque habitant morbi tristique senectus et netus et.</p>
Run Code Online (Sandbox Code Playgroud)
如何使生成的内容("#my-id")可选,以便用户可以突出显示并复制它?
看看这个非常简单的代码
<!DOCTYPE html>
<html>
<head>
<style>
p::before {
content: "Before - ";
}
</style>
</head>
<body>
<p>Hello</p>
<p>Bye</p>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
Css ¨Before -"在每个开头添加<P>并像这样呈现

如果使用鼠标选择文本(对于复制粘贴),则可以选择原始文本,但不能选择由css添加的Before或Aftter文本.

我有一个非常具体的要求,我需要允许用户选择带有mosue的Before文本.你会怎么做?