I have these elements – [.myCheckBox1, .myCheckBox2, ...]
And these elements – [.myCheckBoxList1, .myCheckBoxList2, ...]
How do I make the code pluggable so I don’t have to duplicate the bulk?
Ideally what I would like to have is
[FUNCTION]
$('.myCheckBox1, .myCheckBox2, etc').[FUNCTION]
$('.myCheckBoxList1, .myCheckBoxList2, etc').[FUNCTION]
Code below is what I am wanting to modify:
<script type="text/javascript">
$(document).ready(function () {
$(".myCheckBox1").click(function () {
$(".myCheckBoxList1").change();
});
$(".myCheckBoxList1").change(function () {
var moneys = 0;
$(this).find(":checked").each(function () {
moneys += parseInt($(this).attr('value'));
});
$('.OMG').html(moneys.toString());
});
});
</script>
You could make a jquery plugin, or you could use the same class for all checkboxes (
.myCheckBox) and the same class for all checkbox lists (.myChecBoxList). If you post your html I could give you an example.