I have some code that looks like this:
$('#clearSelections').click(function(e) {
$("#isAcheckbox").removeAttr("checked");
redrawTableofListings();
});
<a href="#" id="clearSelections">clear selections</a>
<input type="checkbox" id="isAcheckbox" checked>
// when the user clicks on the checkbox, doSomeThing happens.
basically, when the user clicks on the href, i want to use jquery to make the href handle the checkbox the same way as though the user just put a check in the checkbox.
Does this make sense? When I use "r开发者_运维问答emoveAttr" it just removes the checkbox, and doesen't redraw the form.
Thanks in advance! and be safe with fireworks this weekend!
It seems you always want to deselect the checkbox when the link is clicked (at least this is what I infer by the text clear selections). Then this will do it:
$('#clearSelections').click(function(e) {
e.preventDefault(); // don't follow the link
$("#isAcheckbox").prop("checked", false);
redrawTableofListings();
});
DEMO
Use
$("#isAcheckbox").trigger('click');
精彩评论