Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 848
user746679 Avatar asked May 10 '11 11:05

user746679


1 Answers

$('#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'
       })
    );
like image 178
fearofawhackplanet Avatar answered Oct 13 '22 11:10

fearofawhackplanet