There is a global listener on specific input type:
$('input[type["radio"]').on('change', function() { ... });
But I have another more specific radio
input with its own unique_radio
class:
<input type="radio" class="unique_radio" name="unique_radio">
It also has its own click listener:
$('.unique_radio').on('click', function() { ... });
When I click it, both listeners trigger the functions, but I need only the function with the unique_radio listener to be triggered.
I have tried using stopImmediatePropagation
and off
as seen here:
Best way to remove an event handler in jQuery?
But that did not seem to work
2
Answers
Your selector is not working with my jquery but you can see below my sample so you can use it directly. You can use this to ignore input with unique_radio class. Use :not() explain with this you dont have to use preventDefault or return false.
My code;
Here is if you attach event listener to all radio
If you want to remove listener on one radio with a particular class you can do it in different way
Here you restrict the execution only for radios which hasn’t class
unique_radio
Here if you want to remove the handler