Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery UI button - how change style and icon checked buttons?

<script type="text/javascript">
    jQuery(document).ready(function($){
        $('.date').datepicker($.datepicker.regional['cs']);
        $(".votePollState").button({ icons: {primary:'ui-icon-closethick'},text: false });
    });
</script>

HTML code:

<input type="checkbox" class="votePollState" id="point-1"/><label for="point-1">Choice 1</label>

<input type="checkbox" class="votePollState" id="point-1"/><label for="point-1">Choice 1</label>

I need setting some icons for state of checkbox, no checked checkbox has other icon and checked checkbox has other. No if i check checkbox, this has some icon but only change border color.

Something use ON/OF switch button on iPhone.

THX

like image 734
Pitrsonek Avatar asked Dec 08 '10 07:12

Pitrsonek


1 Answers

You could add a .change() handler that took the .checked state of the checkbox and assigned the icon based on it, like this:

$(".votePollState").button({ 
    icons: {primary:'ui-icon-closethick'},
    text: false 
}).change(function() {
    $(this).button("option", { 
        icons: { primary: this.checked ? 'ui-icon-check' : 'ui-icon-closethick' }
    });
});

You can test it out here.

like image 155
Nick Craver Avatar answered Nov 15 '22 12:11

Nick Craver