|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
<html>
<head> <script> function toggle(id) { if( document.getElementById(id).style.display=='none' ){ document.getElementById(id).style.display = ''; }else{ document.getElementById(id).style.display = 'none'; } } </script> </head> <body> <span onClick="toggle('hidethis');">toggle</span><br /><br /> <table border="1"> <tr> <td>Always Visible</td> </tr> <tr id="hidethis"> <td>Hide this</td> </tr> <tr> <td>Always visible</td> </tr> </table> </body> </html> Above will show/hide second row. But I need a script that can hide multiple rows in a table (even with multiple ids/names). Something like this: <html> <head> <script> function toggle(id) { if( document.getElementById(id).style.display=='none' ){ document.getElementById(id).style.display = ''; }else{ document.getElementById(id).style.display = 'none'; } } </script> </head> <body> <span onClick="toggle('hidethis');">toggle</span><br /><br /> <table border="1"> <tr id=hidethis"> <td>Hide this</td> </tr> <tr id="hidethis"> <td>Hide this</td> </tr> <tr> <td>Always visible</td> </tr> </table> </body> </html> But in this case js only hide the first row. |
|
#2
|
|||
|
|||
|
Problem is solved, thanks!
|
|
#3
|
||||||
|
||||||
|
Quote:
how was this solved? i'm running into the same problem.. similar javascript code but it only hides the first element with that id. javascript Code:
a checkbox calls the function.. thanks for the help. couldn't find the solution anywhere after searching for a bit.. |
|
#4
|
||||
|
||||
|
IDs should be unique. You could use a class instead.
P.S. In the future, please start a new thread instead of resuming an ancient one.
__________________
Spreading knowledge, one newbie at a time. Learn CSS. | PHP includes | X/HTML Validator | CSS validator | Dynamic Site Solutions Design/program for Firefox (and/or Opera), apply fixes for IE, not the other way around. Check out my blog. |
|
#5
|
|||
|
|||
|
show/Hide Multiple rows
Can you please give an example of how you are calling this function using checkbox/radio button please? A working example will be great.
I am very new to html/javascript and want to implement this functionality in one of my web form that I am doing at the moment. Thanks for your help Quote: |
![]() |
| Viewing: Dev Shed Forums > Web Design > JavaScript Development > show/hide multiple rows in a table |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|