Toggle navigation
Bootsnipp
Bootstrap
For
CSS Frameworks
Bootstrap
Foundation
Semantic UI
Materialize
Pure
Bulma
References
CSS Reference
Tools
Community
Page Builder
Form Builder
Button Builder
Icon Search
Dan's Tools
Diff / Merge
Color Picker
Keyword Tool
Web Fonts
.htaccess Generator
Favicon Generator
Site Speed Test
Snippets
Featured
Tags
By Bootstrap Version
4.1.1
4.0.0
3.3.0
3.2.0
3.1.0
3.0.3
3.0.1
3.0.0
2.3.2
Register
Login
"Input to Table Row (Add and Remove)"
Bootstrap 3.3.0 Snippet by
kai1313
3.3.0
jQuery
table
input
Preview
HTML
CSS
JS
View Full Screen
Fork
Fork this
8.9K
 
5 Fav
Post to Facebook
Tweet this
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css"> <script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/js/bootstrap.min.js"></script> <script src="//code.jquery.com/jquery-1.11.1.min.js"></script> <!------ Include the above in your HEAD tag ----------> <div class="container"> <div class="row"> <h2>Create your snippet's HTML, CSS and Javascript in the editor tabs</h2> </div> <div class="row"> <div class="col-lg-2"> <label>Name</label> </div> <div class="col-lg-4"> <div class="form-group"> <input id="name" type="text" class="form-control" /> </div> </div> </div> <div class="row"> <div class="col-lg-2"> <label>Address</label> </div> <div class="col-lg-4"> <div class="form-group"> <input id="addr" type="text" class="form-control" /> </div> </div> </div> <div class="row"> <div class="col-lg-2 col-lg-offset-2"> <button id="addBtn" class="addBtn form-control btn btn-primary"> Add to Row </button> </div> </div> <br> <div class="row"> <div class="col-lg-12"> <table id="example" class="table table-bordered"> <thead> <tr> <th class="col-lg-1 text-center">No</th> <th class="col-lg-3 text-center">Name</th> <th class="col-lg-7 text-center">Address</th> <th class="col-lg-1 text-center">Actions</th> </tr> </thead> <tbody> </tbody> </table> </div> </div> </div>
#example table { counter-reset: rowNumber; } #example table tr > td:first-child { counter-increment: rowNumber; } #example table tr td:first-child::before { content: counter(rowNumber); min-width: 1em; margin-right: 0.5em; }
$(document).ready(function(){ var i = 1; $(".addBtn").click(function(){ var name = $("#name").val(); var addr = $("#addr").val(); var markup = "<tr><td>"+i+"</td><td>" + name + "</td><td>" + addr + "</td><td><button class='btn btn-small delBtn'>Hapus</button></td></tr>"; $("table tbody").append(markup); i++; }); $(function () { $("table").on("click", ".delBtn", function () { $(this).closest('tr').remove(); }); }); });
Questions / Comments:
Post
Posting Guidelines
Formatting
- Now
×
Close
Donate
BTC: 12JxYMYi6Vt3mx3hcmP3B2oyFiCSF3FhYT
ETH: 0xCD715b2E3549c54A40e6ecAaFeB82138148a6c76