I want the color of the rest of the spans to change every time the button is clicked, since with this example it only chooses one (the first) and not the others, what is missing?
function color() {
var color = document.querySelector(".content > span");
color.style.color = "red";
}
<div class="content">
<span>1</span>
<span>2</span>
<span>3</span>
</div>
<br/>
<button onclick="color()">Agregar color</button>
You would have to get all the spans with querySelectorAll and then loop through the array with forEach so you can change the color of each span.