I have the following code: http://jsfiddle.net/0Lp4oqn6/
On <input type='radio' name='radio' class='radio' value='on'>
Off <input type='radio' name='radio' class='radio' value='off'>
$('.radio').on('change', function() {
alert( $(this).val() )
}).trigger('change')
It's a simple set of 2 radio inputs and an event handler for when the radio input value changes. There is also a .trigger('change') in order to trigger the event handler to happen once when the page loads.
When the page loads, the event handler is triggered twice. The first alert will say on and the second alert will say off. But when I manually click the radio buttons, the change handler is not triggered twice.
Why is the event handler being triggered twice when using .trigger('change')? Why is the behavior different when doing it manually? What is the proper way to programmatically trigger the event handler without it happening twice?