jquery - how to display hexcolor onclick corresponding colobox Javascript? -


i have variable this,

var colours = [     { name: 'yellow', hex: '#ffff00' },     { name: 'lawngreen', hex: '#7cfc00' },     { name: 'aqua', hex: '#00ffff' },     { name: 'fuchsia', hex: '#ff00ff' },     { name: 'blue', hex: '#0000ff' },     { name: 'red', hex: '#ff0000' }       ]; 

i have function ,

$(function() {     $('li').live('click', function()     {          $('.activecolour').css('background-color', $(this).css('background-color'));            });      var $palette = $('ul');     (var = 0; < colours.length; i++)     {         $palette.append($('<li />').css('background-color', colours[i].hex));     } }); 

but while click on particular color, not need rgb color, need hex color in variable or alert do,this document.execcommand please help.

    red = parseint(your_red_value).tostring(16);     green = parseint(your_green_value).tostring(16);     blue = parseint(your_blue_value).tostring(16);     if(red == 0)         red = '00';     if(green == 0)         green = '00';     if(blue == 0)         blue = '00';     var hex_value = ('#' + red + green + blue).touppercase(); 

rgb hex converter

edit: want

var color = $(this).css('background-color').substring($(this).css('background-color').indexof('(')+1,$(this).css('background-color').indexof(')')).split(','); var hex_color ='#'+ parseint(color[0]).tostring(16) + parseint(color[1]).tostring(16) + parseint(color[2]).tostring(16) ; 

js fiddle


Comments

Popular posts from this blog

.htaccess - First slash is removed after domain when entering a webpage in the browser -

Automatically create pages in phpfox -

c# - Farseer ContactListener is not working -