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

207
Views
Highlighting Todays Work Day of the Week in an HTML Table using only CSS/Javascript/Jquery

I would like my computer to automatically highlight todays day of the week in a table row.

The table has all the weekdays in a separate row, and has a fixed number of seven rows, starting with the least pleasant day of all days, Monday or Maandag in Dutch.

Lets say its Tuesday today or Dinsdag in Dutch, then the second row should be highlighted like so:

enter image description here

However, the problem is that instead of todays day, the next day is highlighted. Probably I've overlooked something small. The solution can be onlly in HTML/CSS/JS/JQuery and not in PHP. I have made a demo of my half-working half-defective exemaple:

https://jsfiddle.net/u0bvtzd1/4/

workday();

function workday() {
  var d = new Date().getDay();
  document.getElementById("day-"+d).classList.add('today');    
}
.today { 
  background-color: #FFD700 !important; 
}

table {
    border-collapse: collapse;
    width: 100%;
    border-spacing: 0;
    margin: .5em 0;
}

th, td {
    padding: 1em;
    text-align: left;
    border-bottom: 1px solid #ddd;
    border-color:black;
    border-style:solid;
    border-width:1px;
    overflow:hidden;
    word-break:normal;
}

tr:hover {background-color: #EEE}
<table id="weekdagtabel">
    <tbody>
        <tr id="day-1">
            <td>Maandag</td>
        </tr>
        <tr id="day-2">
            <td>Dinsdag</td>
        </tr>
        <tr id="day-3">
            <td>Woensdag</td>
        </tr>
        <tr id="day-4">
            <td>Donderdag</td>
        </tr>
        <tr id="day-5">
            <td>Vrijdag</td>
        </tr>
        <tr id="day-6">
            <td>Zaterdag</td>
        </tr>
        <tr id="day-7">
            <td>Zondag</td>
        </tr>
    </tbody>
</table>


about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Happens because Monday is the first day of the week not 0th.

Start numbering ids from 1 not 0

about 4 years ago · Juan Pablo Isaza Report

0

The getDay() function returns a number from 0 to 6, indicating Sunday to Saturday. Since, the id values are from Monday to Sunday, shift the numbers cyclically backwards by 1 using modulo operator. By performing the shift, Sunday(0) from the getDay() becomes Sunday(6) in the HTML.

workday();

function workday() {
  var d = new Date().getDay();
  d = (d + 6)%7
  document.getElementById("day-"+d).classList.add('today');    
}

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!