How do i create dynamic Checkbox in jQuery? [duplicate]
I need to create dynamic checkbox using jQuery. How do i do that? Any code snippet will be helpful.
$('#containerId').append('<input type="checkbox" name="myCheckbox" />');
where containerId
is the id of the DOM element you want to add the checkbox to.
Or alternative syntax...
$('#containerId')
.append(
$(document.createElement('input')).attr({
id: 'myCheckbox',
name: 'myCheckbox',
value: 'myValue',
type: 'checkbox'
})
);
精彩评论