Solved

hide show table rows cross browser

Posted on 2006-11-19
6
221 Views
Last Modified: 2008-02-01
I need a javascript & css way to hide or show a row of a table dynamically dreated table.ASAP
0
Comment
Question by:calorisplanitia
  • 3
  • 3
6 Comments
 
LVL 33

Accepted Solution

by:
hongjun earned 500 total points
Comment Utility
try something like this

<script>
function ShowHide(tr, flag) {
    if ( flag == 1 )
        tr.style.display = '';
    else if ( flag == 2 )
        tr.style.display = 'none';
}
</script>

<table border="1">
<tr id="tr1">
    <td>1, 1</td>
    <td>1, 2</td>
</tr>
<tr id="tr2">
    <td>2, 1</td>
    <td>2, 2</td>
</tr>
</table>

<br>

<input type="button" value="Show TR1" onclick="ShowHide(document.getElementById('tr1'), 1)">
<br>
<input type="button" value="Hide TR1" onclick="ShowHide(document.getElementById('tr1'), 2)">
<br>
<input type="button" value="Show TR2" onclick="ShowHide(document.getElementById('tr2'), 1)">
<br>
<input type="button" value="Hide TR2" onclick="ShowHide(document.getElementById('tr2'), 2)">
0
 

Author Comment

by:calorisplanitia
Comment Utility
Perfect Solution & cross bowser compatible
Thankx hongjun
0
 

Author Comment

by:calorisplanitia
Comment Utility
A modification if u can tell me
the aboce solution works fine , but can i use a plus minus image to toggle rows between visible & invisible instead of different buttons
Like if it is visible the  plus image show else minus image shows
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 33

Expert Comment

by:hongjun
Comment Utility
try something like this

<script>
function ShowHide(tr, btn) {
      var flag;

      flag = tr.style.display == '' ? 2 : 1;

      if ( flag == 1 ) {
            tr.style.display = '';
            btn.value = 'Hide';
      }
      else if ( flag == 2 ) {
            tr.style.display = 'none';
            btn.value = 'Show';
      }
}
</script>

<table border="1">
<tr id="tr1">
      <td>1, 1</td>
      <td>1, 2</td>
</tr>
<tr id="tr2">
      <td>2, 1</td>
      <td>2, 2</td>
</tr>
</table>

<br>

<input type="button" value="Hide" onclick="ShowHide(document.getElementById('tr1'), this)">
<br>
<input type="button" value="Hide" onclick="ShowHide(document.getElementById('tr2'), this)">
0
 

Author Comment

by:calorisplanitia
Comment Utility
Thanks a lot.
0
 
LVL 33

Expert Comment

by:hongjun
Comment Utility
No problem
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

When applying CSS to your HTML, there are many different ways to select which element(s) the CSS applies to.  Some of these selectors are more commonly known and used than others - Here are the more common ones: #X - Matches an ID of X .X - Matche…
Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer …
In this Micro Tutorial viewers will learn how to create a CSS image sprite (In a later tutorial, viewers will learn how to use CSS and HTML to create a navigation menu using this sprite) Open a new Photoshop document with a width of (Icon width)x(N…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now