Skip to content

Instantly share code, notes, and snippets.


codingwithsara/index.html Secret

Created Nov 10, 2018
What would you like to do?
【jQuery】テーブル Tr 行を動的に追加・削除・並び替え・値を取得する方法
<!DOCTYPE html>
<html lang="ja">
<meta charset="utf-8">
<link rel="stylesheet" href="">
.container {
width: 500px;
margin: 100px auto;
input {
width: 300px;
font-size: 18px;
margin: 10px;
padding: 10px;
.remove {
width: 30px;
height: 30px;
font-size: 20px;
background-color: tomato;
color: white;
border: none;
border-radius: 15px;
#addRow, #getValues {
width: 130px;
height: 40px;
font-size: 16px;
background-color: lightseagreen;
color: white;
border: none;
margin: 20px;
button:hover {
cursor: pointer;
tr:hover {
cursor: move;
<div class="container">
<td><input type="text" name="name"></td>
<td><button class="remove">-</button></td>
<td><input type="text" name="name"></td>
<td><button class="remove">-</button></td>
<button id="addRow">+ 追加</button>
<button id="getValues">値を取得</button>
<script src=""></script>
<script src=""></script>
var html = '<tr><td><input type="text" name="name"></td><td><button class="remove">-</button></td></tr>';
$(document).on('click', '.remove', function() {
var values = [];
$('input[name="name"]').each(function(i, elem){
alert(values.join(', '));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment