Can javascript cut out a special part from a class and use it in any other place?

Viewed 37

The question might not be clear, but I shall clear it now. In CSS libraries they use classes such as "bg-blue", "text-red", I am especially talking about TailWind. But these classes are limited, if someone want a new color he / she has to go with CSS. So finally I stuck to an idea. Let's take an example :

HTML :

 <h1 class="cbg-008eff"></h1>
/* cbg = Custom Background */

JS :

 I dont know what to write here....

Actually I want JavaScript to get every classes in the html document which starts with "cbg-", therefore it should understand that a background is to be placed, and the rest part after "cbg" is the value to set. Can this be done ?

Thanks In Advance

1 Answers

You could split the class ID as a string by the '-' using the Javascript Split function, not sure how you could get the class ID tho but then you can get the Colour ID as Ramon said. Then use this to implement it: https://www.w3schools.com/js/js_htmldom_css.asp

Related