有没有办法使用jQuery 选择/操作CSS伪元素,如::before和::after(以及带有一个分号的旧版本)?
例如,我的样式表具有以下规则:
.span::after{ content:'foo' }
Run Code Online (Sandbox Code Playgroud)
如何使用jQuery将'foo'更改为'bar'?
是否可以通过JavaScript更改CSS伪元素样式?
例如,我想动态设置滚动条的颜色,如下所示:
document.querySelector("#editor::-webkit-scrollbar-thumb:vertical").style.background = localStorage.getItem("Color");
Run Code Online (Sandbox Code Playgroud)
而且我也希望能够像这样告诉滚动条隐藏:
document.querySelector("#editor::-webkit-scrollbar").style.visibility = "hidden";
Run Code Online (Sandbox Code Playgroud)
但是,这两个脚本都返回:
未捕获的TypeError:无法读取null的属性'style'
还有其他方法可以解决这个问题吗?
跨浏览器的互操作性并不重要,我只需要它在webkit浏览器中工作.
我想在调用mobileValidate()后更改此占位符的颜色.
<input type="text" class="form-control" name="InputMobile" id="Mobile" placeholder="Enter Mobile Number" onblur="mobileValidate()"required>
Run Code Online (Sandbox Code Playgroud)
JavaScript函数是
function mobileValidate(){
var x = document.getElementById("Mobile");
if ((x.value).match(re)){
alert("mobile Number is valid");
}
else{
alert("mobile no is not valid");
x.value="";
x.placeholder.style.color="red";
}
}
Run Code Online (Sandbox Code Playgroud)