Dali
Dali

Reputation: 7882

Append CSS to head?

I want to add some css classes in head Tag, with jQuery (and not a css file like Jquery add css to head)

My css classes are like this:

#control1 { width:60px; height:55px; background:url(../images/logo1.png) no-repeat; float:left; }
#control1.selected {background:url(../images/logo1_aktiv.png) no-repeat;}

Thanks for help.

Upvotes: 1

Views: 1249

Answers (2)

Marcelo Biffara
Marcelo Biffara

Reputation: 831

this is what you need to do, append your style to the head tag

var yourClasses="#control1 { width:60px; height:55px; background:url(../images/logo1.png) no-repeat; float:left; }
#control1.selected {background:url(../images/logo1_aktiv.png) no-repeat;}";

$("document").ready(function(){
    $("head").append("<style type='text/css'>"+yourClasses+"</style>");
});

Upvotes: 3

dsgriffin
dsgriffin

Reputation: 68626

You can append it to the head section using appendTo(), and then selecting "head"

$("<style type='text/css'> .boldYellow{color:yellow; font-weight:bold;} </style>").appendTo("head");

Upvotes: 2

Related Questions