Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
////////////////////////////////////////////////////////////////////////////////
//
// 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) {
}
}
Owner

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