Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

127
Vistas
How can i reset my document.getElementById color value

I'm trying to change the color from red to blue but when the red color come its unchangeable

var colorvalue=0;
var sizevalue;
function CG()
{
    colorvalue ++;
    if (colorvalue==0)
    {
        document.getElementById("testd").style.color = "blue";
    }
    else if(colorvalue==1)
    {
        document.getElementById("testd").style.color = "red";
    }
    if(colorvalue > 1)
    {
        colorvalue = 0;
    }
}

I already got the answer but how do i have more colors

Thanks for seeing my question and if you do thanks for answering

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

i edit a bit of your code. try below

var colorvalue=0;
var sizevalue;
function CG()
{
    colorvalue ++;
    if (colorvalue % 2 == 0)
    {
        document.getElementById("testd").style.color = "blue";
    }
    else
    {
        document.getElementById("testd").style.color = "red";
    }
}

Used modulo operation: So if there is a remainder of colorvalue, element will be red.

about 4 years ago · Juan Pablo Isaza Denunciar

0

An alternative method would be to use CSS rather than setting the style directly on the element using JavaScript.

Initialise your text with the color red, and then toggle a blue class on/off using classList.

const test = document.querySelector('.test');
const button = document.querySelector('button');
button.addEventListener('click', handleClick, false);

function handleClick() {
  test.classList.toggle('blue');
}
.test { color: red; }
.blue { color: blue; }
<p class="test">This is a test</p>
<button>Change color</button>

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda