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

364
Vistas
Tabla HTML: cambie el color de fondo del encabezado a su color original

Cuando hago una selección del menú desplegable, se ejecuta un script y cambia el color de fondo del número seleccionado en el encabezado de la tabla.

¿Cómo volvería a cambiar el color a su color de fondo original después de hacer una nueva selección?

 function doIt() { var array = [10, 20, 30, 40, 50]; var a = document.getElementById("select").value; var found = array.findIndex(function (element) { return element >= a; }); document.getElementById("b").value = found; document.getElementById('t').rows[0].cells[found].style.backgroundColor="#FF0000"; }
 th { border: 2px solid #999; padding: 0.5rem; text-align: left; background-color: goldenrod; }
 <label for="Select">Select Number:</label> <select id="select" onchange="doIt()";> <option>Select</option> <option>10</option> <option>20</option> <option>30</option> <option>40</option> <option>50</option> </select> <input type="text" id="b"> </p> <table id="t"> <tbody> <tr> <th>10</th> <th>20</th> <th>30</th> <th>40</th> <th>50</th> </tr> </tbody> </table>

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

0

Primero debe "desmarcar" otras celdas:

 function doIt() { var array = [10, 20, 30, 40, 50]; var a = document.getElementById("select").value; var found = array.findIndex(function (element) { return element >= a; }); document.getElementById("b").value = found; var cells = document.getElementById('t').rows[0].cells; for(var i = 0; i < cells.length; i++) { cells[i].style.backgroundColor="goldenrod"; } cells[found].style.backgroundColor="#FF0000"; }
 th { border: 2px solid #999; padding: 0.5rem; text-align: left; background-color: goldenrod; }
 <label for="Select">Select Number:</label> <select id="select" onchange="doIt()";> <option>Select</option> <option>10</option> <option>20</option> <option>30</option> <option>40</option> <option>50</option> </select> <input type="text" id="b"> </p> <table id="t"> <tbody> <tr> <th>10</th> <th>20</th> <th>30</th> <th>40</th> <th>50</th> </tr> </tbody> </table>

Y le recomendaría que no cambie la propiedad de estilo (color de fondo) directamente, sino que agregue/elimine la clase para el elemento. Con class puede adjuntar tantas reglas CSS como desee.

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