jquery change attribute of icheck plugin

纵饮孤独 提交于 2019-12-06 15:00:00

Lets say you have checkboxes in this format:

<input type="checkbox" class="my_checkbox" data-label="Check me" />

Than you can change your icon and text this way:

var checkboxClass = 'checkbox_cls';
$('.my_checkbox').each(function(i) {
    var thisCheckbox=$(this);
    thisCheckbox.iCheck({
        checkboxClass: checkboxClass,
        insert: '<div class="icheck_line-icon"></div><span class="insert_label">' + thisCheckbox.data("label") + '</span>'
    });
    var thisIcon = thisCheckbox.siblings('.icheck_line-icon');
    var thisLabel = thisCheckbox.siblings('.insert_label');
    thisCheckbox.on('ifChecked', function(e){
        thisIcon.addClass('icon-checked');
        thisLabel.html('Im checked');
    });
    thisCheckbox.on('ifUnchecked', function(e){
        thisIcon.removeClass('icon-checked');
        thisLabel.html('Not checked');
    });
});

Take a look at this Fiddle.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!