I'm working with a form with a radio button which is part of a set of radios and just one can be selected at a time(no problem with the single selection). One of those radios must fire a code each time it's selected a diferent code when it is unselected (another radio is selected), im using .change
method and it fires the code when you click it, but not when it looses the selection. What i want is to toggle or be able to know when it looses the selection.
I could do it adding code to the other radios .change
method but there are many sets of radios and it would be painful, i'm looking for a one time config.
Edit
The markup is made of ASP MVC Razor engine like this:
@Html.RadioButtonFor(x => x.SomeModel, new { @class = "special-radio" })
@* Other radios but without the 'specia-radio' class *@
js:
// logging
$(function(){
$('.special-radio').change(function(){
console.log('change');
});
});
The string change only appears when you click the 'special-radio' radio.
There is no event triggered when a radio is unchecked, because it would be redundant. Try this instead:
http://jsfiddle.net/hmartiro/g4YqD/1/
It puts a change event on the set of radios and just fires one event if the selected radio is special and another event otherwise.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With