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

142
Vistas
Troubles with hiding cells with javascript function

I have a table where I want to hide cells for more than a certain week. For this I use a function hideWeekCells. It works well when I am using just number instead of currentweek here -> _el.dataset.week > 24 (it works well), but when I tried to change it to dynamic variable current week. There is a problem. Function starts to hide cells at 17 weeks instead of stopping at 24 weeks.

function hideWeekCells(){

        const myAnchor = document.getElementById("myAnchor"); 
        currentweek = myAnchor.dataset.currentweek;     
        
        let weeks = document.querySelectorAll("[data-week]")
        //console.log( 'weeks : ', weeks ); 
        let weeks_array = Array.from( weeks ).filter((_el)=> _el.dataset.week > current week);
        console.log( 'weeks_array final : ', weeks_array ); 
        weeks_array.forEach(element => {
          element.style.display = 'none';
        });       
};

I tried to convert currentweek to numbers with currentweek.valueOf();, but it did not help.

Is it a problem with javascript and my function or maybe it is a problem with my table?

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

0

dataset returns a string by default, so you need to convert them to numbers by Number() for your number comparisons.

Another side note, you should define currentweek with const or let to scope that variable into the function.

function hideWeekCells(){

        const myAnchor = document.getElementById("myAnchor"); 
        const currentweek = Number(myAnchor.dataset.currentweek);     
        
        let weeks = document.querySelectorAll("[data-week]")
        //console.log( 'weeks : ', weeks ); 
        let weeks_array = Array.from( weeks ).filter((_el)=> Number(_el.dataset.week) > currentweek);
        console.log( 'weeks_array final : ', weeks_array ); 
        weeks_array.forEach(element => {
          element.style.display = 'none';
        });       
};
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