Vignesh Pichamani Vignesh Pichamani - 7 months ago 30
Javascript Question

Internal CSS using jquery

Good Day!!!

I am trying to add the

css using jquery
. when i viewing the code using firebug. It looks like in inline css format. But i want to load the internal css property using jquery.
Is it possible to add the internal css using jquery.

$('selector').css('color','#fff');


It appear like For example

<p style="color:#fff"></p>


I want to load as with

<style type="text/css">
p {
color:#fff;
}
</style>


Not sure, how to do it any one review and advise.

Thanks

enter image description here

Answer

Yes you can, just append a style tag to the head:

$("head").append('<style type="text/css">p {color:#fff;}</style>');

see example here jsfiddle