tags:

views:

606

answers:

4

i want to add css to head tag and it should reflect the page like i have text box on my page when user add background image url in this text box on keyup css is created in head tag for body background. css for body tag is successfully added in the start of head tag but no affect on page background :(.

question is can i add css at the end of head tag ? it will change my body background ?

i am doing this using jquery, Please help

+2  A: 

Can't you simply change the css attribute directly with jQuery?

 $(document).ready(function(){   
      ("body").css({'background-color' : 'yellow'});
 });
yoavf
Thanks Yoavf but i want to add couple of css not only for body background. can you help me ?
Yasir
No problem, just check out http://docs.jquery.com/CSS/css, you can change as much css as you need
yoavf
A: 

The head tag contains meta information of the page. It is not visual so adding css to it will have no effect.

jQuery does not add anything to the head tag at runtime, it manipulates the DOM tree that the browser created.

Kees de Kooter
I think he meant he's adding a css block to the head tag with jquery...
yoavf
yup i will add couple of css to head tag with jquery
Yasir
that will change the complete page layout customized page layout by user Thanks Kees de kooter
Yasir
A: 

check your css, you may be resetting the background color through a linked style sheet after the css you want to add is added...

Adding it at the end of the head tag will allow it to override the settings in your CSS style sheet correctly.

Mauro
Thanks Mauro that's exactly what i am asking how i will ad couple of css at the end of head tag, is it will reflect my changes to page using jquery or i hav to do more stuff ?
Yasir
+1  A: 

got solution using code and syntax below.

multiple class and id selectors can be added to change the complete layout of page.

it will only change the background image

$("head").append("<style type=\"text/css\" charset=\"utf-8\">body{background:url("+yourimage variable +") top repeat-x;}");

and multiple css class can be added using below

$("head").append("<style type=\"text/css\" charset=\"utf-8\">body{background:url("+bgimg+") top repeat-x;}#modulebasicInfo{background:#000;}");
Yasir