开发者

How to count toggled buttons in jqueryui after a click event

I need to count how many buttons are toggled using the jqueryui checkbox button option - .buttonset(). This needs to happen when a button is toggled.

I a开发者_Go百科dded a unique class to the labels before applying the button set and have set a click event on it.

It fires fine, however it is firing before the jqueryui has processed the click so the result is out of date. How do I apply the click event after jqueryui has done its job?

$(".button-set").click(function(){
    var selected = $("#offer_list_4 label[aria-pressed=true]").length; // out of date
});


A better way to achieve this is to bind an event handler to the change event of the inputs themselves (this is still triggered even though jQueryUI is doing some trickery with the labels). For example:

$("#offer_list_4 input:checkbox").bind("change", function() {
    var selected = $("#format > input:checkbox:checked").length;
});

Check out a working example here: http://jsfiddle.net/andrewwhitaker/TGR68/

Takes advantage of the :checked selector and the :checkbox selector.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜