cambiar el background color de un span con javascript in javascript

To change the background color of a span using JavaScript, you can use the style.backgroundColor property. First, select the span element using a query selector and then set its background color to the desired value, like this:

index.tsx
let mySpan = document.querySelector('span'); // selects the first span element on the page

mySpan.style.backgroundColor = "red"; // change the background color to red
168 chars
4 lines

This code will change the background color of the first span element on the page to red. If you want to select a specific span element, you can add an ID or a class to it and use that to select it with the query selector.

related categories

gistlibby LogSnag