Mental Jetsam

By Peter Finch

Archive for May, 2007

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" ;

Posted in javascript | 1 Comment »