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
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.