Mental Jetsam

By Peter Finch

Toggle display of DIV in IE and Mozilla

Posted by pcfinch on May 8, 2007

The following code will toggle the display (show/hide) of a division in both IE 5.5+ and Mozilla Firefox and can be used for menus, TOC’s etc. This is simple, but useful. If your looking for a really good collection of cross browser Javascript functions for manipulating HTML and the DOM then check out prototype and if you want a really good overview of the Javascript language, along with some good stories and history of the language, you must see these videos from Dougles Crockford .

function td(d)
   if(document.getElementById) {
      var o = document.getElementById(d) ;
      if(( == "block") || ( == "")) = "none" ;
      else = "block" ;

One Response to “Toggle display of DIV in IE and Mozilla”

  1. Johnson said

    This does not work in IE 7.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: