You can artificially initiate a “change” on switches from the same group so that the original binding handler comes out and displays “unchecked”. The trick is to avoid getting stuck in an infinite loop by recursively re-triggering the event, we can avoid this by ignoring man-made events that lack the originalEvent property:
$("input[type=radio]").on("change", function (e) { var $this = $(this); //all inputs with the same name var $targetInputSelector = $("input[name=" + $this.attr("name") + "]"); //check if the handler was fired "naturally" //if yes, trigger the change handler "artificially" for inputs with the same name if (e.hasOwnProperty('originalEvent')) { //exclude the element that was changed "naturally" //from the subset of all the elements with the same name $targetInputSelector.not($this).triggerHandler("change"); } });
This code works when added on top of your current handler and satisfies the requirements without changing my selector so that it matches both inputs and then looks at the ID criteria;)
http://jsfiddle.net/a73tn/24/
ov
source share