开发者

How do i create dynamic Checkbox in jQuery? [duplicate]

开发者 https://www.devze.com 2023-03-05 06:42 出处:网络
This question already has answers 开发者_如何学编程here: How to create a radio button dynamically with jQuery?
This question already has answers 开发者_如何学编程here: How to create a radio button dynamically with jQuery? (8 answers) Closed 1 year ago.

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'
       })
    );
0

精彩评论

暂无评论...
验证码 换一张
取 消