Can I rely on the color of the item?

I have many such conditions in my codes: (conditions based on the color of the element)

if ( $(elmnt).css("color") == "rgb(134, 134, 134)" ) {
    // do stuff
}

I recently heard:

relies on the color element incorrectly. Because different browsers return a different color. How:

  • rgb (0,0,0)
  • #000000
  • black

It's true? anyway, as I said, I have a lot of conditions in my JS code, as described above, and now I do not know what to do. Any suggestion?

Note. Changing all of these conditions in my codes seems like a nightmare.:-(

+4
source share
2 answers

You can use this RGB parser for JavaScript:

http://www.phpied.com/rgb-color-parser-in-javascript/

( ):

var color = new RGBColor('darkblue');
if (color.ok) { // 'ok' is true when the parsing was a success
    // alert channels
    alert(color.r + ', ' + color.g + ', ' + color.b);
    // alert HEX and RGB
    alert(color.toHex());
    alert(color.toRGB());
}
+4

- , , , . CSS-, , , , , .

, , , , .

, JavaScript- , , , , , , .

-, , - :

- , , . , .

"", , , .

getBooks(), , : " !" , - , .

, ? , , , ... , , - , , getBooks(), , , , , .

, , - " ", " " " ". NPC MMO - , , , , , . , , , , , .

-1
source

Source: https://habr.com/ru/post/1655675/


All Articles