I have some radios in my page,and I want to do something when the checked radio changes,however the code does not work in IE:
$('input:radio').change(...);
And after googling,people suggest use the click instead. But it does not work.
This is the example code:
<html> <head> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script> <script type="text/javascript"> $('document').ready( function(){ $('input:radio').click( function(){ alert('changed'); } ); } ); </script> </head> <body> <input type="radio" name="testGroup" id="test1" />test1<br/> <input type="radio" name="testGroup" id="test2" />test2<br/> <input type="radio" name="testGroup" id="test3" />test3</br> </body> </html>
It also does not work in IE.
So I want to know what is going on?
Also I am afraid if it will retrigger the change event if I click a checked radio?
UPDATE:
I can not add comment,so I reply here.
I use IE8 and the link Furqan give me also does not work in IE8. I do not know why...
Now, to detect when that radio box is changed, you can easily call the jQuery 'change' event inside your jQuery document ready function: $(document). ready(function(){ $('#my_radio_box'). change(function(){ alert('Radio Box has been changed!
A radio button fires the change event after you select it. How it works: First, register an event handler to the change event of the body . When a radio button is clicked, its change event is bubbled to the body.
This code worked for me:
$(function(){ $('input:radio').change(function(){ alert('changed'); }); });
http://jsfiddle.net/3q29L/
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