The SitePoint Forums have moved.

You can now find them here.
This forum is now closed to new posts, but you can browse existing content.
You can find out more information about the move and how to open a new account (if necessary) here.
If you get stuck you can get support by emailing forums@sitepoint.com

If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Beginner: Hide TR on page load

Hi,

I want to have Javascript hide a table row (tr) when the page is called, then have links to show/hide the tr as a toggle.

The show/hide links work fine, but I can't get the tr to be hidden when the page loads. I'm trying to do this with an external (not inline) function so that I can eventually put all my Javascript into it's own file. Can anyone see how to make this work?

The "var" declaration in the script needs to be on it's own line. You can't populate it at the same time as declaring it.

No, it doesn't need to be on separate lines. The problem was the "then" keyword, not that.

Using body's inline onload attribute is bad practice. Using inline event handlers on other elements is not best practice, because it's best to put all JavaScript, including events, in external .js files. It's even worse to use them on <body> because they will overwrite any events for window defined in other JavaScript code blocks. I suggest you read up on Unobtrusive JavaScript.