Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org
#

Q1376 Using just the id of a layer how can I check that it is visible or hidden?

You are here: irt.org | FAQ | DHTML | Q1376 [ previous next ]

Try:

<html>
<head>

<style><!--
.hidden { position:relative; visibility:hidden; }
.visible { position:relative; visibility:visible; }
//--></style>

<script language="JavaScript"><!--
function getVisible(id) {
    if (document.layers)
        return document.layers[id].visibility == 'show' ? true : false;
    else if (document.all)
        return document.all[document.all.tags('div')[id].id].style.visibility == 'visible' ? true : false;
}

function getHidden(id) {
    return !getVisible(id);
}

function test() {
    var output = '';
    output += 'layer1 visible : ' + getVisible('layer1') + '\n';
    output += 'layer1 hidden : ' + getHidden('layer1') + '\n';
    output += 'layer2 visible : ' + getVisible('layer2') + '\n';
    output += 'layer2 hidden : ' + getHidden('layer2') + '\n';
    alert(output);
}
//--></script>

</head>

<body>

<span id="layer1" class="hidden">layer1 is hidden</span>
<span id="layer2" class="visible">layer2 is visible</span>

<form>
<input type="button" value="test" onClick="test()">
</form>

</body>
</html>

©2018 Martin Webb