Change row table color with javaScript

Posted by Slim Mils on Stack Overflow See other posts from Stack Overflow or by Slim Mils
Published on 2012-12-19T16:55:37Z Indexed on 2012/12/19 17:03 UTC
Read the original article Hit count: 157

Filed under:
|
|
|
|

I try to change the background of rows in my table with javaScript but it's not working. This is my code. However I tried to create my table with html and it's work. P.S : I want to use webkit.

Help please.

Code :

var table = document.getElementById("tab");
var rowCount = table.rows.length;


for(var i=0;i<6;i++) {     
   row = table.insertRow(rowCount);
   row.id = "row"+i;
   cell1 = row.insertCell(0);
   var content = document.createElement("output");                
   content.innerHTML = i ;
   cell1.appendChild(content);
   rowCount++;
}


 $(document).ready(function(){
        $('td').each(function(i) {     
             $('#tab').on('click', '#row'+i, function(){
                document.getElementById("row"+i).style.background = 'white';
                 //alert(i);
             });   
        });   

     //example2
     $('#td1').on('click', function(){
                document.getElementById("td1").style.background = 'white';
             });   
 }); 

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery