Create a CSS rule / class with jQuery at runtime

You can create style element and insert it into DOM

$("<style type="text/css"> .redbold{ color:#f00; font-weight:bold;} </style>").appendTo("head");
$("<div/>").addClass("redbold").text("SOME NEW TEXT").appendTo("body");

tested on Opera10 FF3.5 iE8 iE6

Leave a Comment