To change the background color of a span
element using JavaScript, you can set the style.backgroundColor
property of the element.
Here's an example code snippet that demonstrates how to do it:
index.tsx90 chars3 lines
In this example, the background color of the span
element with id="mySpan"
is turned to red.
Alternatively, you can also apply a CSS class to the span
element using the classList.add()
method and define the background color in the CSS.
Here's an example code snippet that demonstrates how to do it:
index.tsx92 chars3 lines
And in your CSS file:
45 chars4 lines
gistlibby LogSnag