Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

111
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!