Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

javascript change table row color based on value

var rows = document.getElementById("trans_separate").getElementsByTagName("tbody")
  [0].getElementsByTagName("tr");

    // loops through each row
    for (i = 0; i < rows.length; i++) {cells = rows[i].getElementsByTagName('td');

            if (cells[0].innerHTML == 'R')
                rows[i].className = "red";

            if (cells[0].innerHTML == 'Y')
                rows[i].className = "yellow";           
 }
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #javascript #change #table #row #color #based
ADD COMMENT
Topic
Name
7+5 =