if div clicked, html5 color inputs values should set clicked div color , background color values.
i tried code
$(function() { $("#changeme").on('click', function() { $('#designer-javascript-color').val($(this).css("color")); $('#designer-javascript-backcolor').val($(this).css("background-color")); }); });
selected item color: <input type="color" id="designer-javascript-color" /> <br>selected item background color: <input type="color" id="designer-javascript-backcolor" /> <br/> <div id="changeme" style='color:white;background-color: blue'> click here</div>
after clicking in click me both inputs have still black colors. how fix white , blue colors apper in inputs ?
testcase @ http://jsfiddle.net/bpc2w43w/
convert rgb value hex before use it:
function rgbtohex(rgb) { var = rgb.split("(")[1].split(")")[0].split(","); return "#" + a.map(function(x) { x = parseint(x).tostring(16); return (x.length == 1) ? "0"+x : x; }).join(""); } $(function () { $("#changeme").on('click', function() { $('#designer-javascript-color').val(rgbtohex($(this).css("color"))); $('#designer-javascript-backcolor').val(rgbtohex($(this).css("background-color"))); }); });
<script src="http://code.jquery.com/jquery-1.11.3.js"></script> selected item color: <input type="color" id="designer-javascript-color" /> <br> selected item background color:<input type="color" id="designer-javascript-backcolor" /> <br/> <div id="changeme" style='color:white;background-color: blue'> click here</div>
Comments
Post a Comment