Skip to content

Instantly share code, notes, and snippets.

@webdood
Created May 18, 2010 19:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save webdood/405381 to your computer and use it in GitHub Desktop.
Save webdood/405381 to your computer and use it in GitHub Desktop.
////////////////////////////////////////////////////////////////////////////////
//
// showOrHide([object|string] oHTMLElement, boolean bShowOrHide)
// Shows or Hides an HTMLElement.
// You can pass in the id to an object or the actual object
//
////////////////////////////////////////////////////////////////////////////////
function showOrHide(oHTMLElement, bShowOrHide) {
try {
if (typeof(oHTMLElement)=="string") {
oHTMLElement = document.getElementById(oHTMLElement);
}
if (oHTMLElement && oHTMLElement.style) {
if (bShowOrHide == 'inherit') {
oHTMLElement.style.visibility = 'inherit';
} else {
if (bShowOrHide) {
if (oHTMLElement.nodeName == 'TR') {
oHTMLElement.style.visibility = 'inline-table';
} else {
oHTMLElement.style.visibility = 'visible';
}
} else {
oHTMLElement.style.visibility = 'hidden';
}
try {
if (bShowOrHide) {
oHTMLElement.style.display = 'block';
} else {
oHTMLElement.style.display = 'none';
}
}
catch (ex) {
}
}
}
}
catch (ex) {
}
}
@webdood
Copy link
Author

webdood commented May 18, 2010

showOrHide algorithm

Making it easier for me to look up my own most useful block of code for displaying/hiding elements. This is the same bit of code I wrote for Microsoft that shipped with Vista and now Windows 7 with the Sidebar gadgets.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment