Created
November 21, 2018 12:47
-
-
Save shajanjp/7d4236171caf01591a985290a619ce9c to your computer and use it in GitHub Desktop.
Multiple inuputs in html form
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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Semantic Starter</title> | |
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.4.1/semantic.min.css"> | |
</head> | |
<body> | |
<div class="ui container"> | |
<div class="ui stackable grid"> | |
<div class="four wide column"> | |
<div class="ui form"> | |
<!-- Add spec input --> | |
<div class="fields spec"> | |
<div class="seven wide field"> | |
<input type="text"> | |
</div> | |
<div class="seven wide field"> | |
<input type="text"> | |
</div> | |
<div class="two wide field"> | |
<!-- remove spec button --> | |
<button class="ui basic icon button remove-spec"> | |
<i class="red trash icon"></i> | |
</button> | |
</div> | |
</div> | |
<!-- Add spec button --> | |
<button class="ui basic icon button add-spec"> | |
<i class="green add icon"></i> | |
</button> | |
</div> | |
</div> | |
</div> | |
</div> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.4.1/semantic.min.js"></script> | |
<script> | |
let specMarkUp = `<div class="fields spec"> | |
<div class="seven wide field"> | |
<input type="text"> | |
</div> | |
<div class="seven wide field"> | |
<input type="text"> | |
</div> | |
<div class="two wide field"> | |
<button class="ui basic icon button remove-spec"> | |
<i class="red trash icon"></i> | |
</button> | |
</div> | |
</div>`; | |
$('.add-spec').on("click", function() { | |
$(specMarkUp).insertBefore(".add-spec"); | |
}); | |
$('body').on("click", ".remove-spec", function(){ | |
this.closest('.fields').remove(); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment