I have the following:
$(document).ready(function() { $("#select-all-teammembers").click(function() { $("input[name=recipients\\[\\]]").attr('checked', true); }); });
I'd like the id="select-all-teammembers"
when clicked to toggle between checked and unchecked. Ideas? that aren't dozens of lines of code?
settings:id/switch_widget\"]"). getAttribute("Checked"); If the element is disabled then you will see the Result Data as "false" and if it is enabled then you will see the "true." You can use the element identifier: //*[@text="ON"] if there is only one toggle element/switch enabled on the screen.
click(function() { var checkBoxes = $("input[name=recipients\\[\\]]"); checkBoxes. prop("checked", !
You can write:
$(document).ready(function() { $("#select-all-teammembers").click(function() { var checkBoxes = $("input[name=recipients\\[\\]]"); checkBoxes.prop("checked", !checkBoxes.prop("checked")); }); });
Before jQuery 1.6, when we only had attr() and not prop(), we used to write:
checkBoxes.attr("checked", !checkBoxes.attr("checked"));
But prop()
has better semantics than attr()
when applied to "boolean" HTML attributes, so it is usually preferred in this situation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With