This is my jQuery script:
$("input[type=radio]:checked").live("click", function() {
$(this).attr("checked",false);
});
I want to make all my radio button can be checked and unchecked. The code suppose to trigger ONLY when checked radio being clicked. But somehow, any radio click (whether it's checked or not) will trigger this event. It's as if the browser will check the radio first and then run my script.
If I alert($("input[type=radio]:checked").size())
, it gave me the correct count.
I'm testing the code in FF4 but I hope the solution can cater for IE as well.
Ok, since my question seems confusing, this is the working code for what I want, BUT it requires additional custom attribute which I hope can avoid.
<input type="radio" name="group1" value="1" isChecked="false"/>
<input type="radio" name="group1" value="2" isChecked="false"/>
<input type="radio" name="group1" value="3" isChecked="false"/>
<script>
$(document).ready(function(){
$("radio").click(function(){
if($(this).attr("isChecked")=="false"){
$(this).attr("isChecked","true");
$(this).attr("checked",true);
}
else{
$(this).attr("isChecked","false");
$(this).attr("checked",false);
}
});
});
</script>