0

Trying to check the border-right-color value with jQuery sorta like so:

if ($(this).css("border-right-color") == "#000") {
    // Do some magic
}

But that doesn't work. console.loging() the value of $(this).css("border-right-color") says rgb(0,0,0).

So, how do I write this conditional check?

Wells
  • 10,415
  • 14
  • 55
  • 85

1 Answers1

0

Use the below function found here

if (rgb2hex($(this).css("border-right-color")) == "#000") {
    // Do some magic
}


function rgb2hex(rgb){
 rgb = rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
 return "#" +
  ("0" + parseInt(rgb[1],10).toString(16)).slice(-2) +
  ("0" + parseInt(rgb[2],10).toString(16)).slice(-2) +
  ("0" + parseInt(rgb[3],10).toString(16)).slice(-2);
}

Take a look here for a working example

What have you tried
  • 11,018
  • 4
  • 31
  • 45