Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not able to switch state #8

Closed
renege opened this issue May 17, 2015 · 4 comments
Closed

Not able to switch state #8

renege opened this issue May 17, 2015 · 4 comments

Comments

@renege
Copy link

renege commented May 17, 2015

I have multiple checkboxes with the plugin enabled. I wanna do something like;

$(document).on('click', '#everything', function(){

    $.ajax({
        type: 'POST',
        url: '/toggle-all',
                complete: function() {
                    // toggle all to active state....
                   alert(' all checkboxes  active in state');
                    $('.onoffswitch-checkbox').something();
        }
    });
});
@renege
Copy link
Author

renege commented May 18, 2015

The following works:

$('.onoffswitch-checkbox').attr('checked', 'checked');

But if you wanna re-toggle all to the "off-state", it doesn't work:

$('.onoffswitch-checkbox').removeAttr('checked');

@timmywil
Copy link
Owner

Thanks for opening an issue! You can retrieve all checked checkboxes using the :checked selector...

$('.onoffswitch-checkbox:checked').something();

To toggle checked state, it works the same as with any native checkbox. Note that the checked attribute is not the same thing as the checked property. Have a look at "Attributes vs. Properties" on this page.

@renege
Copy link
Author

renege commented May 18, 2015

@timmywil,

Yes ok, but it is not working like that:

$(document).on('click', '#resetStates', function(){

    $.ajax({
        type: 'POST',
        url: '/disable-all',
        complete: function() {
            $('.onoffswitch-checkbox').removeProp('checked');
        }
    });

});

$(document).on('click', '#enableAll', function(){

    $.ajax({
        type: 'POST',
        url: '/enable-all',
        complete: function() {
            $('.onoffswitch-checkbox').prop('checked');
        }
    });

});

@timmywil
Copy link
Owner

Don't remove the property. Set it to false.

.prop("checked", false)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants