I know there are a few examples in the community where folks have been able to accomplish this, but I’m struggling with my particular example.
I have a script that’s adding a widget on my site, and it’s setting the color in element.style
with the HTML to color: rgb(0, 0, 0);
, I’d like it to be white
.
element.style {
background-color: rgb(123, 104, 238);
height: 44px;
color: rgb(0, 0, 0);
}
And here’s where it’s set in the HTML
<button
type="button"
id="ada-chat-button"
class="button--text button-v2 button--appear"
aria-label="Chat with bot"
title="Chat with bot"
style="
background-color: rgb(123, 104, 238);
height: 44px;
color: rgb(0, 0, 0);
"
>
</button>
Thank you so much in advance for any direction!!
2
Answers
The style attribute always takes precedence over css rules because it is applied directly to the element.
If you want to modify one of the values of a style attribute, you can do it with javascript.
Below is an example with jQuery.
You seem to be confused about how style settings are made. For a simple case you can do it all in the .html file
Try running the code snippet above and you will see, I set
background-color
style property ofbody
to gray,background-color
ofbutton
torgb(123, 104, 238)
andcolor
torgb(0,0,0)
(which is black). Now if you changecolor
ofbutton
towhite
orrgb(255,255,255)
which are the same thing, it will make the font color white. Try playing around with the above code snippet.Now if you have a larger project where you want to specify styles separately, you create a separate
.css
file, and it would look like this…The above snippet does the same thing but the styles are set separately in a CSS file. The "button#ada-chat-button" specifies that the style we are setting only applies to the
button
component withid=ada-chat-button
. (# specifies id see https://www.w3schools.com/cssref/css_selectors.asp). Alternatively we could have specified by class.button.button-v2 {...}
would mean the style applies to everybutton
with classbutton-v2
. In your case, you have set the button to have classesbutton-v2
,button--text
, andbutton--appear
, which I presume have some meaning in whatever css framework you are using.