Reputation: 3323
Is it possible to uncheck a radio button based on class?
$('#button').click(function () {
$("input:radio[class^='.radio2']").each(function(i) {
this.checked = false;
});
});
JsFiddle = http://jsfiddle.net/nPgyd/1/
This doesn't appear to work.
Upvotes: 3
Views: 8342
Reputation: 2248
Try something like this?
$('#button').click(function () {
$("input[type='radio'].radio2").each(function () {
$(this).prop('checked', false);
});
});
Upvotes: 0
Reputation: 10724
This might be helpful for you.
$('#button').click(function () {
$("input:radio.radio2").each(function(i) {
$(this).attr('checked',false);
});
});
Check the link...
Upvotes: 2
Reputation: 467
Yes you can, the syntax required is not nearly as complex as that.
$('#button').click(function ()
{
$(".radio2").each(function(i)
{
this.checked = false;
});
});
Or if you want only inputs with the class radio2 to be affected:
$('#button').click(function ()
{
$("input.radio2").each(function(i)
{
this.checked = false;
});
});
Upvotes: 0
Reputation: 550
Try
$('#button').click(function () {
$(".radio2").each(function(i)
{
this.checked = false;
});
});
Upvotes: 1
Reputation: 3621
HERE is your solution. You only need to remove the braces to compare the class
$("input:radio[class^=radio2]").each(function(i) {
Upvotes: 5