Reputation: 97
The question sums it up ... Here's what I've tried, is there a better way? It works once (selects and deselects once) then stops working ...
<a href="#resources" onclick="$(':radio').each(function(){$(this).attr('checked', true); });">(Select All)</a> <a href="#resources" onclick="$(':radio').each(function(){$(this).attr('checked', false); });">(Deselect All)</a>
Upvotes: 0
Views: 371
Reputation: 2257
You can do it like this:
$("#selectAll").click(function() { $('input:radio').prop('checked', true); });
$("#deselectAll").click(function() { $('input:radio').prop('checked', false); });
No need to use .each
function, since jQuery uses implicit iteration anyway. Here is working jsfiddle
Upvotes: 2
Reputation: 11340
For stuff like this, I recommend:
$('input:radio').each(function() { $(this).prop('checked', false); });
$('input:radio').each(function() { $(this).prop('checked', true); });
Upvotes: 2