How to parse colors in text, if i type #40464f , i would like catch the color and apply it some CSS.
I know how to do that with added markup,
<span data-color=""> #40464f </span>
for example.
But i would like to know if its possible to do that automatically without the needed to add markups manually ?
Not really knowing what’s asked, I’ll just provide a way to match (HEX) colors within an HTML element.
Given HTML:
Use JS:
(Demo)
Update
Demo where the colors are actually used:
HTML:
JS:
Update #2
Based on comments, replacing inline (demo):
HTML:
JS: