例如,我有一个jQuery函数:
function example(){
var trigger = $('.image');
trigger.each(function(e){
// here I want to change the background color of the :after pseudo-element
$(this:after).css('background-color', 'red');
// ^ the above obviously doesn't work
});
}
如何向$(this)
的伪元素添加、更改或删除CSS属性?
发布于 2016-10-21 04:56:32
您无法处理":after“伪元素,因为它不存在于DOM中(对于:same也是如此)。但是您可以使用以下方法创建它:
$(element).after();
然后用JS来处理。
希望它对你有用!
https://stackoverflow.com/questions/40177108
复制