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

101
Views
Set Custom attribute in Js

I am filtering a table and exporting it to excel. To exclude the filtered rows, i have to set the data-exclude="true" in the 'tr'-element

function Search() {
  var input, filter, table, tr, td, i, txtValue;
  input = document.getElementById("myInput");
  filter = input.value.toUpperCase();
  table = document.getElementById("myTable");
  tr = table.getElementsByTagName("tr");
  for (i = 0; i < tr.length; i++) {
    td = tr[i].getElementsByTagName("td")[7];
    if (td) {
      txtValue = td.textContent || td.innerText;
      if (txtValue.toUpperCase().indexOf(filter) > -1) {
        tr[i].style.display = "" ;
//Set here the Code data-exclude="false"
      } else {
        tr[i].style.display = "none";
//Set here the Code data-exclude="true";

      }
    }       
  }
}

``

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

0

You can update attributes for an element using setAttribute function

tr.setAttribute('data-exclude', true)

You can use getAttribute function to get the value of a specific attribute. Note that value is returned as a string and need to be converted to a boolean value in your case to filter

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!