Show/Hide All Elements by Tag Name





12
Date Submitted Mon. Oct. 30th, 2006 2:23 PM
Revision 1 of 1
Beginner Mattkins
Tags CSS | DHTML | JavaScript
Comments 3 comments
Allows you to hide all elements on an HTML page by their tag name. Extremely handy in getting around the "Windowless Elements" problem in IE, which is a bug that puts certain elements, most commonly select boxes, on top of any other element, no matter what. As you can imagine, this causes real problems with DHTML drop-down menus and such like. This is the simplest and quickest fix I've come up with, I simply set this function to run alongside the drop-down and all of the select tags vanish before a menu drops, then I run the show function when the menu retracts.

function showAllByTag(tagName,dispType) {
        var elements = document.getElementsByTagName(tagName);
        var i = 0;
        if (dispType == "") {
                dispType = inline;
        }
        while (i < elements.length) {
                elements[i].style.display = dispType;
                i++;
                }
}
function hideAllByTag(tagName) {
        var elements = document.getElementsByTagName(tagName);
        var i = 0;
        while (i < elements.length) {
                elements[i].style.display = "none";
                i++;
                }
}
 

Matt Atkins

Comments

Comments DRY
Mon. Oct. 30th, 2006 6:26 PM    Scripter SCoon
  Comments DRY?
Mon. Nov. 13th, 2006 8:40 AM    Beginner Mattkins
    Comments (Don't Repeat Yourself)
Mon. Nov. 20th, 2006 1:15 AM    Helper snowdonkey

Voting