javascript - How to list CheckBoxes in a vertical way? -
when create checkbox, want them listed in vertical way, , not horizontal. how able this??
html:
<div id="cblist"> <input type="checkbox" value="first checkbox" id="cb1" /> <label for="cb1">first checkbox</label> </div> <input type="text" id="txtname" /> <input type="button" value="ok" id="btnsave" />
jquery:
$(document).ready(function() { $('#btnsave').click(function() { addcheckbox($('#txtname').val()); }); }); 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); }
include following line:
$('<br/>').appendto(container);
at end of script.
Comments
Post a Comment