I'm coding a solution to add and remove form fiends dynamically.
This is the action plan:
Hit the green "+" button to append another input exactly like it at the end of the form, then the button changes itself to a red "x" button.
Hit the red "x" button and it completely removes the clicked/touched input.
When I hit the first green button, ok. it performs exactly what I want. Same goes to the first red one. The mess starts when I try to remove or add more than one, cause the unique buttons which works are the 2 when the page loads.
I also think I have to do a function to add a new unique class to every input due to back-end database record at the future. but I also don't know how to do it.
Here's a Fiddle: http://fiddle.jshell.net/Ja9yE/2/
$(document).ready(function(){
var newField = '<div class="field-wrapper"><input type="text" class="field" disabled="disabled" /><div class="button-holder"><div class="button-add"><img src="http://www.ricardostrobel.com.br/add-cancel-color.svg"></div></div></div>'
$(document).on("touchend mouseup",".button-add",function(e){
e.stopPropagation(); e.preventDefault();
$(this).removeClass("button-add").addClass("button-cancel");
$(".field").removeAttr("disabled");
$(newField).hide().appendTo("form").fadeIn(500);
});
$(document).on("touchend mouseup",".button-cancel", function(){
$(this).closest(".field-wrapper").fadeOut("fast");
});
});