Search code examples
jquerycolor-picker

Changing css color of a class using jquery using colorpicker


I have a form which has a field which takes in a hex value using colorpicker http://www.eyecon.ro/colorpicker/

I have a div: <div class="ooffer_resort"></div>, the css background color of which I would like to change when I pick a color in color picker. However my script below just won't work. Please can someone help? Many thanks

My form is as follows:

<input name="linkColor" type="text" class="first-name" id="colorpickerField1" value="00ff00" >

and my js is as follows

$(document).ready(function() {              
        $('#colorpickerField1').ColorPicker({
            color: '#0000ff',
            onChange: function (hsb, hex, rgb) {
                $("ooffer_resort").css('background', '#' + hex);
            }
        });
});

Solution

  • Well, it looks like your selector is wrong. ooffer_resort wouldn't be likely to return anything. Did you mean to make that an ID (#ooffer_resort) or a class (.ooffer_resort)?