Saved X
Google login
SignUp with Email
X

Javascript onclick append a new row to table

theindreshverma ( Edited  Sep 29, 03:18 pm )
Login

Javascript innerHTML() method

<html>
<head>
    <title>Append a new row in table</title>
</head>
<body>

<h1>Append a new row in table</h1>
<table id="tb">
    <tr>
        <th>Table heading1</th>
        <th>Table heading2</th>
    </tr>
    <tr>
        <td>Table docuemnt1</td>
        <td>Table docuemnt2</td>
    </tr>
</table>

<br>
<button onclick="app()">Append new row</button>

<script>
function app() {
    var x = document.getElementById('tb');
    
    // get table data
    var d = x.innerHTML;
    
    x.innerHTML=d+'<tr><td>Table docuemnt1</td><td>Table docuemnt2</td></tr>';
}
</script>

</body>
</html>

Sourcecode Tags

More Sourcecodes

More Sourcecodes