Reputation: 10237
Based on answer from a similar question here: How can I dynamically change the background-color html?
...I added this code to an event:
$('html').removeClass('bronzeBackground silverBackground goldBackground').addClass('bronzeBackground');
This partially works, but the color is only changed in part of the page. What must I do to have the entire background of the page use the color? Do I need to also specify 'body' in addition to 'html' as well as perhaps other elements? There must be a one-tag-changes-all approach...
On a related note, I don't know why, but although adding this CSS doesn't work:
#BooksContent #MoviesContent #MusicContent {
background-color: black !important;
}
...adding this in my jQuery after dynamically populating the contents of the div (id="BooksContent") does work:
$('#BooksContent').css('background-color', 'black');
Upvotes: 0
Views: 1955
Reputation: 2562
If you don't want to use maxton's answer you could use
$('.bronzeBackground, .silverBackground, .goldBackground').removeClass('bronzeBackground silverBackground goldBackground');
$('body').addClass('bronzeBackground');
( edit, removed stupid typo )
Upvotes: 2
Reputation: 97678
Which elements are affected by the colour scheme is entirely up to you - setting the background colour of absolutely every element on the page is probably not what you want.
The JS you show is fine, but you then need to work with it in the CSS, where you can either make elements have a transparent background, or list multiple selectors to have the same styles, e.g.
body.silverBackground, body.silverBackground nav, body.silverBackground div#main /* etc */
{
/* CSS for "silver" theme background */
}
body.silverBackground a
{
/* corresponding link colour to match theme */
}
Upvotes: 1
Reputation: 392
For every element on the page, this will work:
$('*').removeClass('bronzeBackground silverBackground goldBackground').addClass('bronzeBackground');
Upvotes: 1
Reputation: 2275
Try this
$(document.body).removeClass('bronzeBackground silverBackground goldBackground').addClass('bronzeBackground');
Upvotes: 1