I am using a combination of javascript/jquery and html to dynamically populate the page with checkboxes. When you click "add", a new checkbox is created. I am now looking for a way to add an undo button that would delete the last checkbox created.
Here is a link to my code on JSFiddle:
Code snippet:
$(document).ready(function() {
$('#btnSave').click(function() {
addCheckbox($('#txtName').val());
txtName.value="";
});
});
function addCheckbox(name) {
var container = $('#cblist');
var inputs = container.find('input');
var id = inputs.length+1;
$('<input />', { type: 'checkbox', id: 'cb'+id, value: name }).appendTo(container);
$('<label />', { 'for': 'cb'+id, text: name }).appendTo(container);
$('<br/>').appendTo(container);
}