SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict
    Join Date
    Jun 2004
    Location
    Montreal
    Posts
    275
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Hiding a <div> in explorer

    Hi,

    is someone know a good way to show/hide a div in explorer as style.display do not work at all for me.

    I also try with visibility but then, it doesn't work in Firefox as I still see the scrollbar

    Help please

  2. #2
    SitePoint Member
    Join Date
    Jul 2007
    Location
    New York, NY
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    here's what i use:
    Code:
    var toggleItem = function(id) {					// receives id of element to toggle
    	if (!document.getElementById) return;		    // make sure the browser can get elements by id
    	var i = document.getElementById(id);		   // get the element to toggle
    	i.style.display = (i.style.display == "block") ? "none" :"block";
    	// the above line checks the current display and sets it to the opposite
    }
    however, i would actually recommend creating a CSS class for each of your two states, in case some day you want to change the behavior (plus, it fits better with the idea of separating content, behavior, and appearance )...
    Code:
    var toggleItem = function(id) {					// receives id of element to toggle
    	if (!document.getElementById) return;		    // make sure the browser can get elements by id
    	var i = document.getElementById(id);		   // get the element to toggle
    	i.className = (i.className == "style1") ? "style2" :"style1";
    	// the above line checks the current class and sets it to the opposite
    }
    there are other ways of deciding which element to hide, of course. for example, if the item to hide is always the next sibling, you could traverse the DOM, but i find this more suitable for generic, site-wide purposes.

    hope this helps,
    Atg
    Last edited by aarontgrogg; Nov 9, 2007 at 13:47.
    Aaron T. Grogg
    aarontgrogg.com/


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •