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

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

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 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!