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):
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