Logic doesn't recognize table cell value

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • uxcrh
    New Member
    • Mar 2013
    • 1

    #1

    Logic doesn't recognize table cell value

    Hello All,

    I have a simple data-table being sourced from an Oracle DB. There is a column whereas each cell contains only one character - "R","Y", or "N".

    The logic is focused on the correct column because I used the "alert(cell[14].innerText); to see my returned values in the browser.

    The issue is when I try to apply a color change on the row background color based on the cell value of either R,Y or N nothing happens...? Here is my code so far, any help would be much appreciated.

    Code:
     
            var rows = document.getElementById("trans_separate").getElementsByTagName("tbody")[0].getElementsByTagName("tr");
            //alert(rows.length);
    
            for (i = 0; i < rows.length; i++) {
                cells = rows[i].getElementsByTagName('td');
    			
              if (cells[14].textContent === 'R') rows[i].className = "red";
              else if (cells[14].textContent === 'Y') rows[i].className = "yellow";
              else if (cells[14].textContent === 'N') rows[i].className = "green";  
            }
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    I would use == and not ===. Also, if innerText works, then I would use that instead of textContent.

    Comment

    • Dormilich
      Recognized Expert Expert
      • Aug 2008
      • 8694

      #3
      note: innerText is IE only, textContent is supported from all others and IE 9+.

      Comment

      • Rabbit
        Recognized Expert MVP
        • Jan 2007
        • 12517

        #4
        You should also be aware that textContent and innerText do not always return the same thing.

        Comment

        Working...