I found this example: http://jsfiddle.net/jaredwilli/tZPg4/4/
$('#addScnt').live('click', function () {
$('<p><label for="p_scnts"><input type="text" id="p_scnt" size="20" name="p_scnt_' + i +'" value="" placeholder="Input Value" /></label> <a href="#" id="remScnt">Remove</a></p>').appendTo(scntDiv);
i++;
return false;
});
$('#remScnt').live('click', function () {
if (i > 2) {
$(this).parents('p').remove();
i--;
}
return false;
});
, and when I'm trying to replicate the result and try the created <a>
are not selected by jQuery
My Fiddle: http://jsfiddle.net/sonicdeadlock/y3ACz/
$(".addItem").on("click", function () {
var newInput = $('<p><input type="text" class="item" placeholder="item"></input><a href="#" class="removeItem">remove</a></p>');
$(this).closest(".category").append(newInput);
});
$(".removeItem").on("click", function () {
$(this).closest("p").remove();
});