Given the following repeated markup in a page:
<div>
<input type="checkbox" id="chk1" />
<div id="div1" >
//stuff to toggle
</div>
</div>
<div>
<input type="checkbox" id="chk2" />
<div id="div2" >
//stuff to toggle
</div>
</div>
How can I get all checkboxes and then dynamically add toggle to the associated div in an event handler for each checkbox?
$(document).ready(function() {
$('input:checkbox').each(
function() {
$(this).bind('click", function() {
//Attach toggle() to associate DIV
//$('#div1').toggle();
});
});
});
Is there a simple way to do this without resorting to either parsing or assuming an ordered list of IDs?