title: Could you please help me to highlight the selected HTML table row created dynamically through java script
body: <p>Below is the JavaScript functionalities addRow() I have used to add the rows dynamically and now am trying to highlight the selected row with red color using rowhighlight() function.</p>
  
  <p>/<em>Function to addRows dynamically to the HTML table</em>/</p>
  
  <pre><code>function addRow(msg)
  {
      var table = document.getElementById("NotesFinancialSummary");
      var finSumArr1 = msg.split("^");
      var length = finSumArr1.length-1;
      alert("length"+ length);
      for(var i=1; i&lt;finSumArr1.length; i++)
      {
  
          var rowValues1 = finSumArr1[i].split("|");
          tb=document.createElement("tbody");
          var tbody=document.createElement("tbody");
          table.appendChild(tbody);
          var tr=document.createElement("tr");
          tbody.appendChild(tr);
          for(var k=0;k&lt;=10;k++)//adding data to table dynamically
          {       
  
              var td=document.createElement("td");
              tr.appendChild(td);
              var element1=rowValues1[k];
              td.innerHTML =element1;
              tr.onclick=function(){
  
              rowhighlight(this);//calling the rowhighlight function
              }
  
          }
  
  
  
         }
  
  
  
  
  }
  
  
       function rowhighlight(x)
      {
  
          var index = x.rowIndex;
          document.getElementById("NotesFinancialSummary").rows     [index].style.backgroundColor = "red";
  
  
  
      }
  </code></pre>