javascript - Change color of a row on onclick of that particular row -


i creating html table dynamically follows:

var table = document.getelementbyid("mytable");              var rowcount = document.getelementbyid("mytable").rows.length;                   var row = table.insertrow(rowcount);                         var cell1 = row.insertcell(0);             var cell2 = row.insertcell(1);             var cell3 = row.insertcell(2);             var cell4 = row.insertcell(3);             var cell5 = row.insertcell(4);              cell1.innerhtml = rowcount;             cell2.innerhtml = "a";             cell3.innerhtml = "b";             cell4.innerhtml = "c";             cell5.innerhtml = document.getelementbyid("select_product_name").value; 

the last column in row ie, cell5 contains id

i want function in such way onclick of row in table should id ie, value of cell5 , full row should change color red.

note: use javascript not jquery

var table = document.getelementbyid("mytable");  var rowcount = document.getelementbyid("mytable").rows.length;        var row = table.insertrow(rowcount);             var cell1 = row.insertcell(0); var cell2 = row.insertcell(1); var cell3 = row.insertcell(2); var cell4 = row.insertcell(3); var cell5 = row.insertcell(4);  cell1.innerhtml = rowcount; cell2.innerhtml = "a"; cell3.innerhtml = "b"; cell4.innerhtml = "c";  var id = document.getelementbyid("select_product_name").value; cell5.innerhtml = id;  row.onclick = function() {     // add css class row     row.classname += ' red';      // alert id     alert(id); }; 

Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -