SteveLacy SteveLacy - 1 month ago 16
CSS Question

Changing body CSS with a jQuery addClass

I am creating a site with a jQuery gallery, and I have the gallery (similar to lightbox) working well.
My question is, can I create a CSS "body class" that I could call from a jQuery event?
This is what I want:
When someone clicks on the image, the gallery appears. Then the body background becomes black, and shrinks to the size of the browser page, and the mainContent disappears only showing the image.
Is there any way to add a body class to the page when a event occurs? Like:

$("div_one").click(function(){
$("body").addClass("the_new_body_css_look");
});


And the CSS:

.the_new_body_css_look {

body {
/* the colors */
}
mainContent {
/* the size */
}
}

Answer

Probably the fastest way to check it would be to try it yourself. The answer is yes you can.