Oto mój HTML:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <link rel="stylesheet" href="./styles/style.css" type="text/css"> <script type="text/javascript"> $(document).ready( function() { $("#page_9w").click( function() { $("#page_9").toggle(); }).toggle(function() { $("#img_9").attr('src','./images/minus.jpg'); }, function() { $("#img_9").attr('src','./images/plus.jpg'); }); $("#page_15w").click( function() { $("#page_15").toggle(); }).toggle(function() { $("#img_15").attr('src','./images/minus.jpg'); }, function() { $("#img_15").attr('src','./images/plus.jpg'); }); $("#page_18w").click( function() { $("#page_18").toggle(); }).toggle(function() { $("#img_18").attr('src','./images/minus.jpg'); }, function() { $("#img_18").attr('src','./images/plus.jpg'); }); } ); </script> </head> <body> <table class="width_table" border="0" cellpadding="0" cellspacing="0"> <tr> </tr> </table> <div id="page_9" style="display: none;"> <table class="width_table" border="0" cellpadding="0" cellspacing="0"> <tr> </tr> </table> <div id="page_15" style="display: none;"> <table class="width_table" border="0" cellpadding="0" cellspacing="0"> <tr> </tr> </table> <div id="page_18" style="display: none;"> <table class="width_table" border="0" cellpadding="0" cellspacing="0"> <tr> </tr> </table> </div> </div> <table class="width_table" border="0" cellpadding="0" cellspacing="0"> <tr> </tr> </table> </div> <table class="width_table" border="0" cellpadding="0" cellspacing="0"> <tr> </tr> </table> <table class="width_table" border="0" cellpadding="0" cellspacing="0"> <tr> </tr> </table> </body> </html>
I mam pytanie odnośnie tego fragmentu kodu:
<script type="text/javascript"> $(document).ready( function() { $("#page_9w").click( function() { $("#page_9").toggle(); }).toggle(function() { $("#img_9").attr('src','./images/minus.jpg'); }, function() { $("#img_9").attr('src','./images/plus.jpg'); }); $("#page_15w").click( function() { $("#page_15").toggle(); }).toggle(function() { $("#img_15").attr('src','./images/minus.jpg'); }, function() { $("#img_15").attr('src','./images/plus.jpg'); }); $("#page_18w").click( function() { $("#page_18").toggle(); }).toggle(function() { $("#img_18").attr('src','./images/minus.jpg'); }, function() { $("#img_18").attr('src','./images/plus.jpg'); }); } ); </script>
Czy da się zrobić za pomocą jednej funkcji aby rozwijała i ukrywała dany element po ID??
Bo teraz muszę definiować każde kliknięcie dla danego elementu a to jest trochę męczące jak jest tego dużo.
Pozdrawiam i proszę o pomoc.