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

115
Vistas
How do i change table zebra pattern colors using <input type='color'/>

I created two color picker to change table colors in html using input, but i don't know how to change those colors based off what user picks in color picker. I really, really don't want to use jquery and i prefer it to be really simple. Also if it's needed you can find that site under: <www.kubera.cba.pl>

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

0

You can use a css variable and change the variable with JavaScript when the color is selected.

const root = document.querySelector(':root');

function setColor (property, value) {
  root.style.setProperty(property, value);
}

document.querySelectorAll("[data-row]").forEach( function(elem) {
  elem.addEventListener("input", function(){
    setColor(elem.dataset.row, elem.value);
  });
});
:root {
  --odd: #CCCC33;
  --even: #EE33CC; 
}

tr:nth-child(even) {
  background-color: var(--even);
}

tr:nth-child(odd) {
  background-color: var(--odd);
}
<table>
<tbody>
  <tr><td>1</td></tr>
  <tr><td>2</td></tr>
  <tr><td>3</td></tr>
  <tr><td>4</td></tr>
  <tr><td>5</td></tr>
</tbody>
</table>

<label for="odd"><input type="color" id="odd" data-row="--odd" value="#CCCC33"/>

<label for="even"><input type="color" id="even" data-row="--even" value="#EE33CC" />

about 4 years ago · Juan Pablo Isaza Denunciar

0

On your input color, put a change event where you can get the new color with "this.value". Now apply the value to the element.

<input onchange="document.getElementById('yourTable').style.backgroundColor = this.value" type='color'/>
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