Advertisement
Guest User

Untitled

a guest
Jan 20th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. <%= button_tag 'Add a new field', id: 'add_correct_answer', type: 'button' %>
  2.  
  3. $(document).ready(function() {
  4. // When the add_button is pressed
  5. $('#add_correct_answer').click(function() {
  6. // Container (already created)
  7. var container = $('.buttons-fields');
  8.  
  9. // Create the input wrapper (input tag + delete button), and append it to `container`
  10. var input_wrapper = $('<div>', { class: 'input-wrapper' }).appendTo(container);
  11.  
  12. // Create an input tag, and append it to input_wrapper
  13. var input = $('<input>', { name: 'correct_answers[]', type: 'text' }).appendTo(input_wrapper);
  14.  
  15. // Create the remove button, append it to input_wrapper, and add a click callback to
  16. // remove the input wrapper if it's pressed.
  17. var remove = $('<span>', { text: 'x' }).appendTo(input_wrapper).click(function() {
  18. input_wrapper.remove();
  19. });
  20. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement