I'm trying to access the CSS :before
and :after
selectors with jQuery. I have tried a few methods, but it seems that the CSS selectors can't be seen by the DOM. What I'm trying to manipulate is to give the element a dynamic background-color
.
For example:
.className:before {background: red;}
At some point, I want to change this color to be dynamic:
$('.clasName:before').css('background-color', bgColor); //this method doesn't work
Also tried this:
$('.clasName').addClass('change').attr('data-background', bgColor);
//this method works only for content property
CSS
.className.change:before {
background: attr(data-background);
}
It's not working as well. Are there any work around for this issue in particular?