Created
March 27, 2016 18:34
-
-
Save tahsingungordu/2dfa360c14e4b9e5128c to your computer and use it in GitHub Desktop.
Add and delete rows with jQuery
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(window).load(function(){ | |
$(function() { | |
var scntDiv = $('#listValue'); | |
var i = $('#listValue').size() + 1; | |
$(document).on('click','#addItem', function() { | |
$('<span><input name="inputName[]" type="text" /> <a id="delItem" href="#">Delete Row</a><br /></span>').appendTo(scntDiv); | |
i++; | |
return false; | |
}); | |
$(document).on('click','#delItem', function() { | |
if( i > 2 ) { | |
$(this).parents('span').remove(); | |
i--; | |
} | |
return false; | |
}); | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="https://code.jquery.com/jquery-2.1.1.min.js"></script> | |
<script src="custom-js.js"></script> | |
<ul class="addDelList"> | |
<li id="listValue"> | |
<input name="inputName[]" type="text"> | |
<a href="#" id="addItem">Add Row</a><br /> | |
</li> | |
</ul> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment