Reputation: 3907
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
Upvotes: 1
Views: 4799
Reputation: 3907
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;}");
Upvotes: 7
Reputation: 4511
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.
Upvotes: 0
Reputation: 7195
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.
Upvotes: 0
Reputation: 21213
Can't you simply change the css attribute directly with jQuery?
$(document).ready(function(){
("body").css({'background-color' : 'yellow'});
});
Upvotes: 3