Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

208
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda