Forum Moderators: open
Any suggestions?
If the content isn't divided into layers, the process can involve searching the document, either once at first, or every time. I thought, seeinmg as you mentioned sitching classNames, whether we could get CSS to do the searching for us.
Here's a demo. It displays content based on the BODY's className.
(*! switch ¦ for unbroken pipe symbol, as usual)
<html>
<head>
<style>BODY * {display: none; }
.perm {display: block;}BODY.all * {display: block;}
BODY.group1 .group1 {display: block;}
BODY.group2 .group2 {display: block;}
BODY.group3 .group3 {display: block;}/*---- Not relevant ----------------------------------*/
DIV{border: solid 1px #aaa; font-family: verdana; width:250px;margin: 15px;}
INPUT{width:150px;}
#buttondiv {position: absolute; left: 500px; top: 50px;width:150px;height:200px; }
#buttondiv *{display:block;}
/*----------------------------------------------------*/
</style>
<script>
// Used this so as to make
// further extensions easier.
//
Function.prototype.prepareArgs = function(delim){
var args = this.arguments[0].constructor == Array
? this.arguments[0] : this.arguments;
var k=0, out=[];
while(k<args.length) out[out.length]=args[k++];
return (delim¦¦delim=='')? out.join(delim) : out ;
}function showGroups()
{
document.body.className = showGroups.prepareArgs(' ');
}</script>
</head>
<body class="group1">
<div class="group1">Group 1 content.</div>
<div class="group2">Group 2 content.</div>
<div class="group3">Group 3 content.</div>
<div class="group1">More group 1 content.</div>
<div class="group2">More group 2 content.</div>
<div class="group3">More group 3 content.</div>
<!-- -->
<div id="buttondiv" class="perm">
<input type="button" value="group1" onclick="showGroups('group1')" />
<input type="button" value="group2" onclick="showGroups('group2')" />
<input type="button" value="group3" onclick="showGroups('group3')" />
<!-- 3 options for multiple groups -->
<input type="button" value="groups 1 & 2" onclick="showGroups(['group1','group2'])" />
<input type="button" value="groups 1 & 3" onclick="showGroups('group1','group3')" />
<input type="button" value="groups 2 & 3" onclick="showGroups('group2 group3')" />
<!-- -->
<input type="button" value="none" onclick="showGroups('')" />
<input type="button" value="all" onclick="showGroups('all')" />
</div>
</body>
</html>