Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the new color value from Input Color after choosing it?

I use Input Color to change the color of the text in a table cell.

I can select the cell, click on the color button, select the color and press enter (on Chrome).

My problem is that the color changes only after I press again on the color button (and the window open again..).

How to change/get the value of the element after selecting the new color without clicking on it again ?

Is this related to the EventListener I use for the Input Color ?

I need to use JavaScript for this, no jQuery.

like image 343
user3450862 Avatar asked Dec 19 '25 06:12

user3450862


1 Answers

You can get input value with onchange event.

jQuery('#color').on('change',function(){
	jQuery('#choosen-color').text(jQuery(this).val());
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<input type="color" id="color">
<div id="choosen-color"></div>

UPDATE

document.getElementById('color').onchange=function(){
	// do whatever you want with value
  alert(this.value);
}
<input type="color" id="color">
like image 71
AlmasK89 Avatar answered Dec 20 '25 18:12

AlmasK89



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!