Problem with radiobutton and jquery
I'm really new to jQuery, so pardon me if this is way too simple. I'm using ASP.NET and WebForms. I generate a group of RadioButtons on code, so what .NET generates is something like this:
-
<span class="block small rdoSmall_Deck_Size">
<input id="ctl00_Main_rdoSmall_Deck_Size" type="radio" name="ctl00$Main$Deck_Size" value="rdoSmall_Deck_Size" />
<label for="ctl00_Main_rdoSmall_Deck_Size">Small (Small)</label>
</span>
Since .NET changes the ids of the controls, I'm trying to find the radiobutton based on the css class to be able to check/uncheck it.
I've tried this:
-
$('.rdoSmall_Deck_Size').attr("checked", "checked");
but since the radiobutton is surrounded by a span element, it puts the checked attribute on the span:
-
<SPAN class="block small rdoSmall_Deck_Size" checked="checked">
<INPUT id=ctl00_Main_rdoSmall_Deck_Size value=rdoSmall_Deck_Size type=radio name=ctl00$Main$Deck_Size>
<LABEL for=ctl00_Main_rdoSmall_Deck_Size>Small (Small)
</LABEL>
</SPAN>
but if I look for the id of the input element like this:
-
$("*[id$='" + s + "']").attr("checked", "checked");
where
s is the string containing the id of the element, it changes the selection of the radiobutton just fine. I was told this is a very slow method, that's why I'm using the css class to find the element but it's not working.
Any idea as to why?
I also tried this:
-
$('input:radio.rdoSmall_Deck_Size').attr("checked", "checked");
and it won't work either. What am I doing wrong?