Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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/3/

JS

workday();

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

HTML

<h2>Werktijden<h2>  

<table>
    <tbody>
        <tr id="day-0">
            <td>Maandag</td>
        </tr>
        <tr id="day-1">
            <td>Dinsdag</td>
        </tr>
        <tr id="day-2">
            <td>Woensdag</td>
        </tr>
        <tr id="day-3">
            <td>Donderdag</td>
        </tr>
        <tr id="day-4">
            <td>Vrijdag</td>
        </tr>
        <tr id="day-5">
            <td>Zaterdag</td>
        </tr>
        <tr id="day-6">
            <td>Zondag</td>
        </tr>
    </tbody>
</table>

>Solution :

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

Start numbering ids from 1 not 0

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading