[javascript] Add table row in jQuery

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>`);
}

_x000D_
_x000D_
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_
_x000D_
_x000D_

Examples related to javascript

need to add a class to an element How to make a variable accessible outside a function? Hide Signs that Meteor.js was Used How to create a showdown.js markdown extension Please help me convert this script to a simple image slider Highlight Anchor Links when user manually scrolls? Summing radio input values How to execute an action before close metro app WinJS javascript, for loop defines a dynamic variable name Getting all files in directory with ajax

Examples related to jquery

How to make a variable accessible outside a function? Jquery assiging class to th in a table Please help me convert this script to a simple image slider Highlight Anchor Links when user manually scrolls? Getting all files in directory with ajax Bootstrap 4 multiselect dropdown Cross-Origin Read Blocking (CORB) bootstrap 4 file input doesn't show the file name Jquery AJAX: No 'Access-Control-Allow-Origin' header is present on the requested resource how to remove json object key and value.?

Examples related to html-table

Table column sizing DataTables: Cannot read property 'length' of undefined TypeError: a bytes-like object is required, not 'str' in python and CSV How to get the <td> in HTML tables to fit content, and let a specific <td> fill in the rest How to stick table header(thead) on top while scrolling down the table rows with fixed header(navbar) in bootstrap 3? Sorting table rows according to table header column using javascript or jquery How to make background of table cell transparent How to auto adjust table td width from the content bootstrap responsive table content wrapping How to print table using Javascript?