Home Articles FAQs XREF Games Software Instant Books About Feedback Search Site-Map
irt.org logo

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

irt.org | Knowledge Base | DHTML | Q1376 [ previous next ]

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

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>

Provide feedback ...
AddThis Social Bookmark Button

Provide feedback ... AddThis Social Bookmark Button


Last Updated: 30th March 2008. Maintained by: Martin Webb
irt.org liability, trademark, document use, privacy statement and software licensing rules apply.
Copyright © 1996-2008 irt.org, All Rights Reserved.