Return to Snippet

Revision: 1026
at August 29, 2006 13:10 by mail_json


Initial Code
<script>
var status=1;
function changeObjectVisibility(objectId, newVisibility) {
    // first get a reference to the cross-browser style object 
    // and make sure the object exists
    var styleObject = getStyleObject(objectId);
    if(styleObject) {
	styleObject.visibility = newVisibility;
	return true;
    } else {
	// we couldn't find the object, so we can't change its visibility
	return false;
    }
}

function getStyleObject(objectId) {
  // checkW3C DOM, then MSIE 4, then NN 4.
  //
  if(document.getElementById && document.getElementById(objectId)) {
	return document.getElementById(objectId).style;
   }
   else if (document.all && document.all(objectId)) {  
	return document.all(objectId).style;
   } 
   else if (document.layers && document.layers[objectId]) { 
	return document.layers[objectId];
   } else {
	return false;
   }
}

function toggle() {

	if (status==1) {
		status=0;		
		changeObjectVisibility('container','visible');
	} else {
		status = 1;
		changeObjectVisibility('container','hidden');
	}
}
</script>

Initial URL

                                

Initial Description
Heres how to use it:

link
sample content under div

Initial Title
Toggle Visibility

Initial Tags

                                

Initial Language
PHP