Search code examples
javascripttooltip

How do I add a tooltip to a dynamically created table row in javascript?


I want to add a tool-tip for each of the table rows that are being created in a HTML table:

document.getElementById("insert").addEventListener("click",function(){
    table.insertRow(table.rows.length);

    //add a tooltip for each row
})

How do I go about it?


Solution

  • you can use setAttribute methods.

    document.getElementById("insert").addEventListener("click",function(){
        //add a tooltip for each row
    var newRow = table.insertRow(table.rows.length);
          newRow.setAttribute("title", "tooltip text");
    })