I have been trying to figure out how to remove the .change()
jquery handler but have had no luck. I am using it to activate some form fields when a radio button is selected, but I don't want it to fire for every subsequent change.
$('.radio').change(function(){
alert("changed");
$('.fields').removeAttr('disabled');
//this is where I try removing the change handler
$(this).off('change');
});
JSfiddle demo
change
// 'this' only removing the handler from the radio button that was changed
$(this).off('change');
to
// removing the handler of all radio button
$('.radio').off('change');
your code
$('.radio').change(function(){
alert("changed");
$('.fields').removeAttr('disabled');
$('.radio').off('change');
});
http://jsfiddle.net/q5jqqgnt/3/
Your code actually works, but only problem is that you are turning off the "Change" event only for the Radio button that you are clicking. Try to use $(".radio").off('change');
instead of $(this).off('change');
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