How to hide other div's than the one selected?

Discussion in 'JavaScript' started by 123GoToAndPlay, Feb 23, 2007.

  1. #1
    I have 3 different layers, which are invisible.

    Depending on a link a layer becomes visible with the corresponding content. How do I hide this layer when another link is clicked?

    part of js
    
    function output(http_request,layerName) {
    			
    			//Check to see if the XmlHttpRequests state is finished.
    			if (http_request.readyState == 4) {
    			//Set the contents of our span element to the result of the asyncronous call.
    				 if (http_request.status == 200) {
    					document.getElementById(layerName).innerHTML = http_request.responseText;
    					closeOthers(layerName);
    				} else {
    					document.getElementById(layerName).innerHTML = "Sorry, currently unavailable";
    					}
                }
    		}
    		
    		function closeOthers(layerName) {
    			
    			var myItem = document.getElementById(layerName);
    
    			if (myItem.style.display != "none") {
    				//items are currently displayed, so hide them
    				myItem.style.display = "none";
    			} else {
    				//items are currently hidden, so display them
    				myItem.style.display = "block";
    			}
    			
    			
    			/*if(document.getElementById != layerName){
    		  		document.getElementById.innerHTML = '';
    		  		document.getElementById.style.visibility = 'hidden';
    			}*/
    		}
    
    Code (markup):
     
    123GoToAndPlay, Feb 23, 2007 IP
  2. DeViAnThans3

    DeViAnThans3 Peon

    Messages:
    785
    Likes Received:
    83
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Should be simple if you use arrays :)

    sample: (just at new line of "function closeOthers(layerName) {")
    Edit the "layer-id-1" etc to the right layer IDs
    
    var layers = Array(3);
    layers[0] = "layer-id-1";
    layers[1] = "layer-id-2";
    layers[2] = "layer-id-3";
    Code (markup):
    Now add before (new line) "/*if(document.getElementById != layerName){":
    var x=0;
    for (x=0; x<3; x++)
    {
    if(layers[x] == layerName)
    {
      // do nothing
    }else{
     layernid = layers[x];
     document.getElementById(layernid).style.display = "none";
    }
    Code (markup):
    hope this helps.

    peace,
    hans
     
    DeViAnThans3, Feb 23, 2007 IP
  3. 123GoToAndPlay

    123GoToAndPlay Peon

    Messages:
    669
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #3
    hi hans,

    Tx for your answer. I am gonna check it out
     
    123GoToAndPlay, Feb 24, 2007 IP
  4. DeViAnThans3

    DeViAnThans3 Peon

    Messages:
    785
    Likes Received:
    83
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Great :) Let me know whether it works or not .. I'm watching this topic ;)
     
    DeViAnThans3, Feb 24, 2007 IP