Click event for dynamic checkbox

by Akram kamal

HTML

<input type="text" id="text">
<div id="test"></div>

JavaScript

$(function(){
var html = '';
html += '<input type="checkbox" id="check" />';
$('#test').html(html);
 
    $('#check').on('click',function(){
        if($(this).prop('checked')){
             $('#text').val('1');
        } else {
             $('#text').val('0');
        }
    });
});