I use Bootstrap and have a form with 2 textfields and 2 checkboxes. With an add-Button, I want to add (per click) an additional textfield with checkbox. Currently I'm using this JS:
$("#addButton").click(function () {
var newTextBoxDiv = $(document.createElement('div'))
.attr("id", 'TextBoxDiv' + counter);
/* TODO: patterns festlegen */
newTextBoxDiv.after().html('<div class="form-group label-floating">' +
'<label class="control-label">Answer' + counter + '</label>' +
'<input type="text" class="form-control"/>' +
'</div><div class="togglebutton"><label><input type="checkbox" checked="">Toggle is on</input></label></div>');
newTextBoxDiv.appendTo("#AnswerGroup");
counter++;
});
It adds successfully the textfield, but the checkbox isn't showing up, only the text "Toggle is on".
How can I solve this? I inserted the JS inside $(document).ready(function () {.
EDIT I think the CSS causes the problem. When I simply add '</div><input type="checkbox" checked=""/></div>', it only shows the checkbox without UI. After adding the rest (like class="togglebutton", I see nothing.