If you had a consistent naming convention, I think something like the following would work:
function setClick() { var id = ""; for(var i = 0; i < arguments.length; i++) { id = arguments[i]; $("#ckbx_"+id).click( function() { $(this).attr("checked") ? $("#opt_"+id).show("medium") : $ ("#opt_"+id).hide("medium"); }); } } setClick("wgmpo", "wgmse", "tydgc", "tydoe", ...); On Feb 11, 3:11 pm, rsmolkin <[EMAIL PROTECTED]> wrote: > Hi, > > I hope someone can help me out a bit. > > I am finding myself doing a lot of code (as I'll paste below). It's > basically the same block of code with different variables. > > What I am trying to do is consolidate all that code into a funciton > where I can declare all the checkboxes I need to create an Click > function for, and then loop through them and generate the click > handler as well as other functions for all of them. > > Here is the code snippet: > > $('#ckbx_wgmpo').click( > function() { > if ($(this).attr("checked") == true){ > > $('table#tbl_wgmpo').show('medium'); > } > else{ > > $('table#tbl_wgmpo').hide('medium'); > } > } > ); > $('#ckbx_wgmse').click( > function() { > if ($(this).attr("checked") == true){ > > $('table#tbl_wgmse').show('medium'); > } > else{ > > $('table#tbl_wgmse').hide('medium'); > } > } > ); > $('#ckbx_wgmoe').click( > function() { > if ($(this).attr("checked") == true){ > > $('table#tbl_wgmoe').show('medium'); > } > else{ > > $('table#tbl_wgmoe').hide('medium'); > } > } > ); > $('#ckbx_tyd').click( > function() { > if ($(this).attr("checked") == true){ > > $('div#tyd_info').show('medium'); > } > else{ > > $('div#tyd_info').hide('medium'); > } > > } > ); > $('#ckbx_tydpo').click( > function() { > if ($(this).attr("checked") == true){ > > $('table#tbl_tydpo').show('medium'); > } > else{ > > $('table#tbl_tydpo').hide('medium'); > } > } > ); > $('#ckbx_tydgc').click( > function() { > if ($(this).attr("checked") == true){ > > $('table#tbl_tydgc').show('medium'); > } > else{ > > $('table#tbl_tydgc').hide('medium'); > } > } > ); > $('#ckbx_tydoe').click( > function() { > if ($(this).attr("checked") == true){ > > $('table#tbl_tydoe').show('medium'); > } > else{ > > $('table#tbl_tydoe').hide('medium'); > } > } > );