How to create a dynamic checkbox in jQuery?

I need to create a dynamic checkbox using jQuery. How should I do it? Any piece of code will be helpful.

+5
source share
2 answers

See the following link: How to dynamically create a switch using jQuery?

Here's how to create a radio button using jQuery, you can change the code to create a checkbox.

+1
source
$('#containerId').append('<input type="checkbox" name="myCheckbox" />');

where containerIdis the identifier of the DOM element to which you want to add this flag.

Or alternative syntax ...

$('#containerId')
    .append(
       $(document.createElement('input')).attr({
           id:    'myCheckbox'
          ,name:  'myCheckbox'
          ,value: 'myValue'
          ,type:  'checkbox'
       })
    );
+17
source

All Articles