How do i create dynamic Checkbox in jQuery?
40,543
$('#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'
})
);
![Admin](/assets/logo_square_200-5d0d61d6853298bd2a4fe063103715b4daf2819fc21225efa21dfb93e61952ea.png)
Author by
Admin
Updated on August 01, 2020Comments
-
Admin almost 4 years
I need to create dynamic checkbox using jQuery. How do i do that? Any code snippet will be helpful.
-
kamilah carlisle almost 4 yearsI really like the literal option for labels but how can I use variables to fill out the tag? For example, var name = name; $('#containerId').append('<label>name</label>');