The answers above are very helpful, but when student refer this link to add data from form they often require a sample.
I want to contribute an sample get input from from and use .after()
to insert tr to table using string interpolation
.
function add(){
let studentname = $("input[name='studentname']").val();
let studentmark = $("input[name='studentmark']").val();
$('#student tr:last').after(`<tr><td>${studentname}</td><td>${studentmark}</td></tr>`);
}
function add(){_x000D_
let studentname = $("input[name='studentname']").val();_x000D_
let studentmark = $("input[name='studentmark']").val();_x000D_
_x000D_
$('#student tr:last').after(`<tr><td>${studentname}</td><td>${studentmark}</td></tr>`);_x000D_
}
_x000D_
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>_x000D_
<!DOCTYPE html>_x000D_
<html>_x000D_
<head>_x000D_
<style>_x000D_
table {_x000D_
font-family: arial, sans-serif;_x000D_
border-collapse: collapse;_x000D_
width: 100%;_x000D_
}_x000D_
_x000D_
td, th {_x000D_
border: 1px solid #dddddd;_x000D_
text-align: left;_x000D_
padding: 8px;_x000D_
}_x000D_
_x000D_
tr:nth-child(even) {_x000D_
background-color: #dddddd;_x000D_
}_x000D_
</style>_x000D_
</head>_x000D_
<body>_x000D_
<form>_x000D_
<input type='text' name='studentname' />_x000D_
<input type='text' name='studentmark' />_x000D_
<input type='button' onclick="add()" value="Add new" />_x000D_
</form>_x000D_
<table id='student'>_x000D_
<thead>_x000D_
<th>Name</th>_x000D_
<th>Mark</th>_x000D_
</thead>_x000D_
</table>_x000D_
</body>_x000D_
</html>
_x000D_