use*_*106 2 jquery jquery-selectors
我有以下CSS:
.example:before {
content: " $ ";
margin-left: 4px;
color: #666;
}
Run Code Online (Sandbox Code Playgroud)
我想使用 jQuery 更改“内容”。我使用什么选择器来访问该元素?
您根本无法直接访问:before或使用 Javascript。:after我知道在运行时修改它们的唯一方法是使用属性,但这违背了让 css 首先添加内容的目的......
超文本标记语言
\n\n<div class="example" title=" $ ">Something in the div</div>\nRun Code Online (Sandbox Code Playgroud)\n\nCSS
\n\n.example:before {\n content: attr(title); /* use the value of the title attribute */\n margin-left: 4px;\n color: #666;\n}\nRun Code Online (Sandbox Code Playgroud)\n\nJavaScript
\n\n$(".example").attr("title", " \xc2\xa3 ");\nRun Code Online (Sandbox Code Playgroud)\n\n\n\n就像我说的,这种否定了选择器的全部意义:before,你也可以简单地使用 Javascript 在前面添加一些东西。