JSFiddle - React, Tailwind, and code Playground

by Alberto LĂłpez Tejeda

HTML

<body>
	<div id="caja">
		<p>Texto cambiando de color</p>
	</div>
	<button onclick="cambiarColor();">Iniciar</button>
	<button onclick="parar();">Parar</button>
</body>

JavaScript

var textoColor;
 
function cambiarColor() {
	textoColor = setInterval(texto, 500);
}
 
function texto() {
	var cajaTexto = document.getElementById("caja");
	cajaTexto.style.color = cajaTexto.style.color == "red" ? "blue" : "red";
}
 
function parar() {
	clearInterval(textoColor);
}