Last active
August 29, 2015 14:08
-
-
Save dacur/5e900bd433d8c9aded06 to your computer and use it in GitHub Desktop.
Adding text boxes dynamically on button click using '.append()'.
This file contains hidden or 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
| $('.fa-times').on('click', function(){ | |
| $(this).closest('li').remove(); | |
| }); |
This file contains hidden or 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
| .pleasantSortLI { list-style: none; height: 51px; } | |
| #sortable { padding-left: 0; } | |
| .pleasantTextBox { width: 80%; float: left; display: inline-block; } | |
| #pleasantIcons { height: 41px; } | |
| .fa-calendar, .fa-times, .fa-arrows { margin-top: 10px; margin-left: 5px; } |
This file contains hidden or 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
| #pagePleasantHome.page | |
| .content | |
| h4.centeredText Pleasant Activity Tool | |
| ul#sortable | |
| li.pleasantSortLI | |
| input(type='text', class='pleasantTextBox', placeholder='Add a pleasant activity') | |
| #pleasantIcons | |
| i.fa.fa-calendar | |
| i.fa.fa-times | |
| i.fa.fa-arrows | |
| button.btn.btn-default.form-control.button.trackit#pleasantAddBtn(type='button') Add Activity | |
| button.btn.btn-default.form-control.button.trackit#pleasantDoneBtn(type='button') Done |
This file contains hidden or 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
| // Adds a text box and 3 FA icons on each btn click | |
| function AddPleasantTextBox(){ | |
| $('#sortable').append('<li class="pleasantSortLI"><input type="text" placeholder="Add a pleasant activity" | |
| class="pleasantTextBox" /><div class="pleasantIcons"><i class="fa fa-calendar"></i><i class="fa fa-times"> | |
| </i><i class="fa fa-arrows"></i></div></li>'); | |
| // When X or 'fa-times' icon is clicked, this LI is removed/deleted from DOM | |
| $('.fa-times').off(); | |
| $('.fa-times').on('click', function(){ | |
| $(this).closest('li').remove(); | |
| }); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment