Skip to content
David Kittell
David Kittell

Application & System: Development / Integration / Orchestration

  • Services
    • Application Development
    • Online Application Integration
  • Code
  • Online Tools
  • Tech Support
David Kittell

Application & System: Development / Integration / Orchestration

Open/Close Elements

Posted on June 12, 2013October 26, 2015 By David Kittell

Sometimes you need to be able to hide elements on a page, the following functions will help with the task of hiding/showing those elements.

function eToggle(anctag, darg) {
	var ele = document.getElementById(darg);
	var text = document.getElementById(anctag);

	//alert(text.id);
	//alert(text.value);

	if (ele.style.display == "block") {
		ele.style.display = "none";
		text.value = " Open ";
	}
	else {
		ele.style.display = "block";
		text.value = " Close ";
	}
}
<input type='button' onclick="javascript:eToggle('atag_1','tblVisitorInfo1');" id='atag_1' value=' Open ' style="display: inline;">
<div id='tblVisitorInfo1' style='display: none;'>Show Me or Hide Me</div>
<a href="javascript:openallelements();" onkeypress="javascript:openallelements();" style="font-size: 8pt;">[ Open All ]</a>
<a href="javascript:closeallelements();" onkeypress="javascript:closeallelements();" style="font-size: 8pt;">[ Close All ]</a>
function openallelements() {
	var divs = document.getElementsByTagName("div");
	for (var i = 0; i < divs.length; i++) {
		//do something to each div like

		if (divs[i].style.display == 'none') {
			divs[i].style.display = 'block';
			//alert(divs[i].getAttribute("id"));
		}
	}

	var array = document.getElementsByTagName("input");
	for (var ii = 0; ii < array.length; ii++) {
		if (array[ii].type == "button") {
			if (array[ii].className == "openclosebutton") {
				array[ii].value = " Close ";
			}
		}
	}
}
function closeallelements() {
	var divs = document.getElementsByTagName("div");
	for (var i = 0; i < divs.length; i++) {
		//do something to each div like
		if (divs[i].style.display == 'block') {
			divs[i].style.display = 'none';
			//alert(divs[i].getAttribute("id"));
		}
	}

	var array = document.getElementsByTagName("input");
	for (var ii = 0; ii < array.length; ii++) {
		if (array[ii].type == "button") {
			if (array[ii].className == "openclosebutton") {
				array[ii].value = " Open ";
			}
		}
	}
}
Originally Posted on June 12, 2013
Last Updated on October 26, 2015
All information on this site is shared with the intention to help. Before any source code or program is ran on a production (non-development) system it is suggested you test it and fully understand what it is doing not just what it appears it is doing. I accept no responsibility for any damage you may do with this code.

Related

Code JavaScript

Post navigation

Previous post
Next post

Related Posts

Azure Red Hat – RHUI Update

Posted on December 27, 2016January 9, 2017

Most of the this script is based on the document “Red Hat Update Infrastructure (RHUI) for on-demand Red Hat Enterprise Linux VMs in Azure” at https://docs.microsoft.com/en-us/azure/virtual-machines/virtual-machines-linux-update-infrastructure-redhat?toc=%2fazure%2fvirtual-machines%2flinux%2ftoc.json My change will first check if the update was already installed, if not it will follow the process to install See updates at: https://gitlab.com/Kittell-RedHat/AzureRepo/raw/master/AzureRedHatRepoUpdate.sh…

Read More

Android Contacts – [MUST HAVE ROOT]

Posted on January 10, 2014October 26, 2015

If you have rooted your phone, there are various ways to run these queries but I choose two ways that work for me. These code snippets will assist you in cleaning up your Android contacts. DISCLAIMER: Backup your contacts before you run any of these queries as I take no…

Read More

FixedSplit

Posted on February 21, 2013October 26, 2015

public static string FixedSplit(string s, int len, string delim) { StringBuilder sb = new StringBuilder(s.Length + (int)(s.Length / len) + 1); int start = 0; for (start = 0; start < s.Length – len; start += len) { sb.Append(s.Substring(start, len)); sb.Append(delim); } sb.Append(s.Substring(start)); return sb.ToString(); } Originally Posted on February…

Read More

Code

Top Posts & Pages

  • PowerShell - Rename Pictures to Image Taken
  • Front Page
  • C# - Start/Stop/Restart Services
  • MacPorts / HomeBrew - Rip CD tracks from terminal
  • PowerShell - Show File Extensions

Recent Posts

  • Javascript – Digital Clock with Style
  • BASH – Web Ping Log
  • BASH – Picture / Video File Name Manipulation
  • Mac OSX Terminal – Create SSH Key
  • Bash – Rename Picture

Top Posts

  • PowerShell - Rename Pictures to Image Taken
  • C# - Start/Stop/Restart Services
  • MacPorts / HomeBrew - Rip CD tracks from terminal
  • PowerShell - Show File Extensions
  • Open On Screen Keyboard (OSK)
  • SQLite - Auto-Increment / Auto Generate GUID
©2025 David Kittell | WordPress Theme by SuperbThemes