jquery - How to add checkboxes dynamically using javascript? -
i use bootstrap , have form 2 textfields , 2 checkboxes. add-button, want add (per click) additional textfield checkbox. i'm using 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 on</input></label></div>'); newtextboxdiv.appendto("#answergroup"); counter++; });
it adds textfield, checkbox isn't showing up, text "toggle on".
how can solve this? inserted js inside $(document).ready(function () {
.
edit think css causes problem. when add '</div><input type="checkbox" checked=""/></div>'
, shows checkbox without ui. after adding rest (like class="togglebutton", see nothing.
the markup checkbox not correct:
<label><input type="checkbox" checked="">toggle on</input></label>
should be
<label><input type="checkbox" checked="" />toggle on</label>
Comments
Post a Comment