0

I'm trying to change backgroundColor based on a input value, however it does not seem to work, when i change the color from the colorpicker even though i can see the input value change?

http://jsfiddle.net/AHZBT/4/

Java Code

$(function() { var bgColor = $('#colorpickerField1').val(); $('body').css("backgroundColor",'#' + bgColor); $('#colorpickerField1').keyup(function() { $('body').css("backgroundColor",'#' + $(this).val()); }); }); 
2
  • 1
    You are listening to keyup, so the backgound color is going to change only if you type something. Commented Oct 6, 2015 at 17:36
  • Working fine for me. Commented Oct 6, 2015 at 17:36

3 Answers 3

4

Use change event:

 $('#colorpickerField1').change(function() { $('body').css("backgroundColor",'#' + $(this).val()); }); 
Sign up to request clarification or add additional context in comments.

Comments

1

If you're looking to change the background in real-time, I pulled this from the documenation:

<input class="color {onImmediateChange:'updateInfo(this);'}" id="colorpickerField1" value="66ff00"> function updateInfo(color) { $('body').css("backgroundColor",'#' + color); } 

http://jscolor.com/try.php#onimmediatechange

Comments

0

Worked ok with blur:

$(function() { var bgColor = $('#colorpickerField1').val(); $('body').css("backgroundColor",'#' + bgColor); $('#colorpickerField1').blur(function() { $('body').css("backgroundColor",'#' + $(this).val()); }); }); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.