Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating CSS :after with jQuery [duplicate]

Tags:

jquery

css

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?

like image 224
user1083320 Avatar asked Feb 06 '12 20:02

user1083320


2 Answers

You can generate a <style> tag and insert it into the <head>:

http://jsfiddle.net/PrBHF/

$("head").append($('<style>div:after { content: " World" }</style>'));
like image 116
Ates Goral Avatar answered Sep 23 '22 00:09

Ates Goral


Why create css using javascrript?

Have the required styles in a css class and then apply the class using jQuery by using addClass method.

like image 25
ShankarSangoli Avatar answered Sep 24 '22 00:09

ShankarSangoli