Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <%= button_tag 'Add a new field', id: 'add_correct_answer', type: 'button' %>
- $(document).ready(function() {
- // When the add_button is pressed
- $('#add_correct_answer').click(function() {
- // Container (already created)
- var container = $('.buttons-fields');
- // Create the input wrapper (input tag + delete button), and append it to `container`
- var input_wrapper = $('<div>', { class: 'input-wrapper' }).appendTo(container);
- // Create an input tag, and append it to input_wrapper
- var input = $('<input>', { name: 'correct_answers[]', type: 'text' }).appendTo(input_wrapper);
- // Create the remove button, append it to input_wrapper, and add a click callback to
- // remove the input wrapper if it's pressed.
- var remove = $('<span>', { text: 'x' }).appendTo(input_wrapper).click(function() {
- input_wrapper.remove();
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement