Skip to content

Instantly share code, notes, and snippets.

@banderson623
Created July 14, 2015 03:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save banderson623/cf01d64ae4a072890c35 to your computer and use it in GitHub Desktop.
Save banderson623/cf01d64ae4a072890c35 to your computer and use it in GitHub Desktop.
Color and Text/Hex Field Pairing
<div class="color-container">
<input type="text" name="hex" class="text-value" />
<input type="color" name="color" class="color-value" />
</div>
<script type="text/javascript">
$('.color-container').on('change keyup', 'input[type="text"], input[type="color"]',
function(){
var $this = $(this);
if($this.attr('type') === 'color'){
$this.siblings('input[type="text"]').val($this.val());
} else {
$this.siblings('input[type="color"]').val($this.val());
}
});
</script>
@banderson623
Copy link
Author

You can see this running at http://jsfiddle.net/banderson623/8hpogmwj/1/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment