17 December 2007

Hide table row


Step 1 - Introduction

Javascript hide table row

Time to time it can happen that you want to make your html table more attractive and more interactive. Let's suppose you want to allow your visitors to hide and show some special rows in your table. Of course you are here because you want to do it without reloading the page. It is possible with javascript to hide table rows and show it again later if you want.

First of all lets create a basic and simple html 3x3 table where the first row contains the column captions. With the following html code:


you will get a table like this:

TH-1TH-2TH-3
cell-11cell-12cell-13
cell-21cell-22cell-23

Ok, that is our starting point. What we want is to add a button to the page to hide table rows. In this case we will hide the caption row.

To do this we will create a Javascript function which will be responsible for hiding and showing the row. Besides this we add a button to the page and it's onClick event will trigger the Javascript function.

Now it's time to make some real coding :)

No comments: