I need to dynamically create my CSS styles for my elements. However, I need to have :after in CSS and I have heard that you cannot modify this in jQuery.
Is this true? Is there anyway around this?
I need to dynamically create my CSS styles for my elements. However, I need to have :after in CSS and I have heard that you cannot modify this in jQuery.
Is this true? Is there anyway around this?
 
    
     
    
    You can generate a <style> tag and insert it into the <head>:
$("head").append($('<style>div:after { content: " World" }</style>'));
 
    
     
    
    Why create css using javascrript?
Have the required styles in a css class and then apply the class using jQuery by using addClass method.
 
    
    Is this true?
Yes. Pseudo-elements created with :after are not part of the DOM and therefore cannot be selected.
Is there anyway around this?
No. Unless you do it without :after (use an actual element, then you can select it/bind events to it).
Edit
Having re-read your question, I think you're actually asking if you can apply :after styles to an element with jQuery. The answer is still no, although you can use addClass to add a new class to the element and define :after styles for that class name.
Edit again
When I've said "no", it seems I'm not entirely correct... see @AtesGorals answer for a nice workaround.
