Search code examples
jqueryhtmlcolor-picker

jQuery live color switcher


I try to make jquery live color switcher but i need to know is it possible add some plugin who change a background color like header or body

Now I use jQuery MiniColors 2.0.


Solution

  • You can use simple javascript to get the element and change the background color using

    document.getElementById('Id name here').style.background = color;
    

    or you can use jQuery and use:

    $('bodyIdOrClassName').css('backgroundColor', '#FF0000');
    

    but with your color of course.

    EDIT: using style.background is better than using .bgColor.

    Using your JsFiddle: add this to the change function:

                    change: function(hex, opacity) {
    
                        // ADD THIS LINE
                        $('body').css('backgroundColor', hex);
                    }
    

    Here's a live example: http://jsfiddle.net/KNWVv/