Mental Jetsam

By Peter Finch

  •  

    May 2007
    M T W T F S S
    « Apr   Jun »
     123456
    78910111213
    14151617181920
    21222324252627
    28293031  
  • My del.icio.us links

  • Flickr Photos

    S5001187

    S5001169

    S5001136

    More Photos
  • Wordpress Stuff

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((o.style.display == "block") || (o.style.display == ""))
         o.style.display = "none" ;
      else
         o.style.display = "block" ;
   }
}

Posted in javascript | 1 Comment »