简体   繁体   中英

How to to select jQuery custom checkbox and perform an action

I am using a jQuery custom Radio and Checkbox from: HERE I am wanting to do Something like: When Check box is selected Perform an action. In order to do that I made:

if($('.main').find('.checked')){
    $('.move').click( function(){
        alert("Hello World");
    });

}

Action Should be if check box is selected or have the class .checked, Clicking on any Button which has .move class will give alert "Hello world". Here .main is the div wrapping everything

But That I have used is not getting correct result. It giving me alert always. Is there any proper way to Select that .checked class and perform my action? Any help or suggestion will be appreciated. [Sorry for not giving js fiddle link or example]

在此处输入图片说明

I'm not familiar with the plugin you're using, but from having a brief look, try this:

$(document).on('click', '.custom-check', function(e){
    if ( $(this).hasClass('checked') ) {
        // Do something
    }
    else {
        // Do something else
    }
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM