Skip to content Skip to sidebar Skip to footer

How Can I Dynamically Change The Background-color Html?

I want to change the background (gradient) of either the html or body in response to an event. Is it possible to change the background-color attribute using jQuery? Or (I have the

Solution 1:

This is how i would do it

$('someElement').click(function(){ // 1var newClass = $(this).attr('toggleColor'); // 2
   $(document.body).removeClass('color1 color2 color3').addClass(newClass); // 3
});

----- Details ------

steps

  1. Add a click event to the element that will toggle a different color
  2. Get the new class name i am assuming that you will have this in a attribute on the element
  3. Remove every color class from the element then add the new one

Post a Comment for "How Can I Dynamically Change The Background-color Html?"