hello all, How can i make this shorter? I need to have 15 altogether. Thanks all. <script type="text/javascript"> $(document).ready(function(){ $("#divextra1").css("display","none"); $("#divcheckme1").click(function(){ if ($("#divcheckme1").is(":checked")) { $("#divextra1").show("fast"); } else { $("#divextra1").hide("fast"); } }); }); $(document).ready(function(){ $("#divextra2").css("display","none"); $("#divcheckme2").click(function(){ if ($("#divcheckme2").is(":checked")) { $("#divextra2").show("fast"); } else { $("#divextra2").hide("fast"); } }); }); $(document).ready(function(){ $("#divextra3").css("display","none"); $("#divcheckme3").click(function(){ if ($("#divcheckme3").is(":checked")) { $("#divextra3").show("fast"); } else { $("#divextra3").hide("fast"); } }); }); $(document).ready(function(){ $("#divextra4").css("display","none"); $("#divcheckme4").click(function(){ if ($("#divcheckme4").is(":checked")) { $("#divextra4").show("fast"); } else { $("#divextra4").hide("fast"); } }); }); $(document).ready(function(){ $("#divextra5").css("display","none"); $("#divcheckme5").click(function(){ if ($("#divcheckme5").is(":checked")) { $("#divextra5").show("fast"); } else { $("#divextra5").hide("fast"); } }); }); </script> HTML:
1-15 Compressed: http://pastebin.com/raw.php?i=0cGkwVSK DEP/Compressed: http://pastebin.com/raw.php?i=CMbX5yx8
<script type="text/javascript"> function showHide(obj1,obj2) { if ($("#"+obj1).is(":checked")) { $("#"+obj2).show("fast"); } else { $("#"+obj2).hide("fast"); } } </script> call the showHide function as follow let say <input id="divcheckme1" name="divcheckme1" onclick="showHide('divcheckme1','divextra1')/> <input id="divcheckme2" name="divcheckme2" onclick="showHide('divcheckme2','divextra2')/> <input id="divcheckme3" name="divcheckme3" onclick="showHide('divcheckme3','divextra2')/> as follows