CSS color selector regardless of presentation

I want to select all the elements on my page with a certain color, say red. I know I can do it like this: $("div[style=color:rgb(255,0,0)]"). However, my problem is that there are various red images, for example. #FF0000and simple red. But any number of spaces in rgb(255, 0, 0)still determines the red color.

I need to do this in a general way that will work for any color and will accept any representation of that color. Is there a way to define such a smart CSS selector?

+4
source share
2 answers

, . , "" (, # FF00000)? , , "" ?

, kukkuz .

, , CSS

0

, jquery /, , . .

, , , , , , , 0 255 ff 00 ..

...

jquery , / , .

, , ( rgb ).

, w3c...

:

$('div').each(function(){
if($(this).css('color') == "rgb(255, 0, 0)" || $(this).css('color') == "#FF0000"){
    $(this).css("color","green");
}
if($(this).css('background-color') == "rgb(255, 0, 0)" || $(this).css('background-color') == "rgba(255, 0, 0, 0)"){
    $(this).css("background-color","green");
}});

Fiddle: https://jsfiddle.net/zdu1adr7/4/

chrome, firefox, edge, .. 11/10/9.

0

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


All Articles