Reputation: 5072
I have an advanced search form on a page and there is also a "clear" button which resets the form. As the form gets cleared I am using this code to un-check the form's checkbox inputs:
$('form#advanced_search :input[type=checkbox]').each(function() { this.checked = false; });
Problem is, this code resets all checkboxes on the page (tested in Chrome and FireFox) instead of just the ones in form#advanced_search.
The same problem also happens using this selector method:
$('form#advanced_search input:checkbox').each(function() { this.checked = false; });
I read somewhere that jQuery has some buggy issues with checkboxes and radios, but does anyone know a method or work around for this?
Upvotes: 1
Views: 12021
Reputation: 5072
It looks like this is a datatables issue specific to my case. So I'll have to dig a bit deeper to solve the problem.The regular selector methods seem to be working with non-auto generated checkboxes on my page.
I'll update here once I track down the bug.
Thanks everyone!
Upvotes: 0
Reputation: 6075
The selector is not correct: Try using:
$('form#advanced_search input[type=checkbox]').each(function() { this.checked = false; });
Upvotes: 1
Reputation: 11820
You're not using the correct selector to get the checkboxes that you want. Try this:
$("#advanced_search input[type='checkbox']").prop("checked", false);
Fiddle: http://jsfiddle.net/R3Rx2/
Upvotes: 3