Is there a selector that can select all elements with a certain color? I want to change all text with color: #1a0dab
to color:00b0f4
.

- 15
- 3
-
How are the styles defined? If inline, you can do `document.querySelectorAll('[style*="#1a0dab"]')` or similar. – Lionel Rowe Sep 22 '20 at 10:26
-
Unfortunately this is just userstyles based on Stylus, not userscripts, so jQuery is out of the question. I should have specified, since all I found while searching on my own was jQuery related. Sorry about that. – disgustingwaste Sep 22 '20 at 10:33
-
Do you mean JavaScript is out of the question, or just jQuery? – Lionel Rowe Sep 22 '20 at 10:40
-
I don't believe userstyles support anything else besides CSS and maybe LESS. – disgustingwaste Sep 22 '20 at 11:49
3 Answers
If the styles are defined inline, you can do this:
[style*="#1a0dab"] {
color: #00b0f4 !important;
}
Demo:
[style*="#1a0dab"] {
color: #00b0f4 !important;
}
<p style="color: #1a0dab">paragraph 1</p>
<p>paragraph 2</p>
<p style="color: #1a0dab">paragraph 3</p>
There's no pure CSS way of doing this if the original styles aren't defined inline.
If you have access to JavaScript, you can do something like the following, though performance will probably be poor if your page has a lot of elements or you need to run the function frequently:
[...document.querySelectorAll('*')]
.filter(el => getComputedStyle(el).color === 'rgb(26, 13, 171)')
Note that you need to use the RGB representation, not the hex version, to check equality.
Here's a demo of the latter approach:
[...document.querySelectorAll('*')]
.filter(el => getComputedStyle(el).color === 'rgb(26, 13, 171)')
.forEach(el => el.style.color = '#00b0f4')
.has-color {
color: #1a0dab;
}
<p class="has-color">paragraph 1</p>
<p>paragraph 2</p>
<p class="has-color">paragraph 3</p>

- 5,164
- 1
- 14
- 27
There is no such selector available in Javascript/jQuery. Perhaps you can: 1 - Update the CSS files and find/replace all instances instead 2 - Add a class to all the required elements and then use the class to target them.

- 482
- 3
- 12
You should make a list of all the tags you need to change color and then with jquery give a unique color change order

- 11
- 5