It is not possible to use jQuery to directly modify the styles of pseudo classes because they cannot be selected. However, a workaround is to inject a new style element into the head section to achieve the desired styling changes.
HTML
<div class="container">
Container
</div>
JS
var redAfter = jQuery('<style>.container:after{border:1px solid #F00; }</style>');
var blueAfter = jQuery('<style>.container:after{border:1px solid #00f; }</style>');
jQuery("#change1").click(function(){
blueAfter.remove();
jQuery("head").append(redAfter);
});
jQuery("#change2").click(function(){
redAfter.remove();
jQuery("head").append(blueAfter);
});
Fiddle Demo
There may be performance issues with this method, especially if there are many pseudo elements that need to be modified. It is advisable to keep track of the injected styles and remove them when no longer needed. Additionally, compatibility across different browsers may vary, although it has been tested to work in Chrome.
If possible, consider using actual objects instead of pseudo elements in your code for better maintainability and performance.