javascript - Jquery checkboxes within containing table selector question -
my current code:
<script type="text/javascript"> function checkall(checked) { $("input[type='checkbox']:not([disabled='disabled'])").attr('checked', checked); } </script> <input type="checkbox" id="cbxselectall" onclick="checkall(this.checked);" />
the short version:
how modify function call , method above check checkboxes inside table containing checxbox form element.
the long version:
i creating webusercontrol containing grid view in asp.net going have delete option. delete series of checkboxes 1 box in header select of them. amounts non asp.net people table header row has checkbox , every row has checxbox.
i have used above code check boxes on entire page. won't work here though because want have multiple of these on page @ once each working independently. know use selector select boxes if id'd table require coding name table uniquely , put name in script block.
really modify script above check checkboxes in containing table of "select all" box. table containing checkbox nested within others don't see being nested within it, or if there , nested table contains checxboxes don't care if selected.
thanks help.
first, don't mix html , javascript. use event handler binding instead.
second, use closest
nearest ancestor element of particular type:
$(document).ready(function(){ $('#cbxselectall').click(function() { $(this) .closest('table') // parent table element .find("input:checkbox:enabled") // find children match selector .attr('checked', this.checked); // set checked value }); });
Comments
Post a Comment