views:

63

answers:

1

Why doesn't $("#RadioButtons:checked").val() - id selector - work in Internet Explorer but $("input:radio[name='RadioButtons']:checked").val() - name selector - does?

<input name="RadioButtons" id="RadioButtons" type="radio" value="1" checked>
<input name="RadioButtons" id="RadioButtons" type="radio" value="2">

<script>
  alert($("#RadioButtons:checked").val());
  alert($("input:radio[name='RadioButtons']:checked").val());
</script>
+6  A: 

IE more-closely follows the standard with regards to this issue. You can't have two elements with the same ID.

BipedalShark
Yes, I ran into a similar problem when one of my coworkers used some hidden fields with the same IDs.
R. Bemrose