I am attempting to manipulate the CSS :before
and :after
selectors using jQuery. Despite trying various methods, it appears that the DOM is unable to access these CSS selectors. My goal is to dynamically change the background-color
of an element.
For instance:
.className:before {background: red;}
Eventually, I aim to update this color dynamically:
$('.clasName:before').css('background-color', bgColor); //this approach does not seem to work
I have also attempted:
$('.clasName').addClass('change').attr('data-background', bgColor);
//this method only affects the content property
CSS
.className.change:before {
background: attr(data-background);
}
Unfortunately, neither of these methods are successful. Is there a workaround for this specific issue?