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'
})
);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With