<分区>
<分区>
例如,我有这个 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 属性?
最佳答案
您不能处理“:after”伪元素,因为它在 DOM 中不存在(与 :before 相同)。但是您可以创建它:
$(element).after();
然后用 JS 处理。
希望对你有用!
关于jquery - 使用像 :after with $(this) 这样的伪元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40177108/