This is my jQuery script:
$("input[type=radio]:checked").live("click", function() { $(this).attr("checked",false); });
I want all my switches to be able to be checked and removed. The code should run ONLY when checking the radio. But somehow, any click on the radio (whether it is installed or not) triggers this event. It is as if the browser first checked the radio and then ran my script.
If I alert($("input[type=radio]:checked").size()) , it gave me the correct score.
I am testing code in FF4, but I hope the solution can serve IE.
Well, since my question seems confusing, this is working code for what I want, but it requires an 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>
source share