Hi all
I’m very new to javascript found a bit of code that almost does what I want, I say almost.. I have spent the day trying out different code and open to something that does the job but kinda become attached to this.
OK I need a script that will control at least 3 different CSS styles of expand/collapse. Think of it as 3 webpages of FAQs on one site, each with a different style, so each would have unlimited entries.
The closest to what I want is offered on [url]http://jdstiles.com/java/expanding/qa.html
Java:
Code:
[CODE]var ids=new Array();
function QAinit(){
if(document.getElementById){
var tids=document.getElementsByTagName(‘div’);
for(i=0;i<tids.length;i++)if(tids[i].className==”question”)ids[ids.length]=tids[i];
for(i=0;i<ids.length;i++)ids[i].onmouseup=setstate;
}}
function setstate(){
for(i=0;i<ids.length;i++){
if(ids[i]==this){
var d=this.parentNode.getElementsByTagName(‘div’)[1];
if(d.style.display==”block”)d.style.display=”none”;
else d.style.display=”block”;
}}}
function expandall(){
if(document.getElementById){
for(i=0;i<ids.length;i++)ids[i].parentNode.getElementsByTagName(‘div’)[1].style.display=”block”;
}}
function collapseall(){
if(document.getElementById){
for(i=0;i<ids.length;i++)ids[i].parentNode.getElementsByTagName(‘div’)[1].style.display=”none”;
}}
window.onload=QAinit;
Basic html
Code:
[CODE]<div class=”primary-container”><!–1st container–>
<div class=”pri-question”> Your first question goes here… </div>
<div class=”pri-answer”> <p>Lorem ipsum dolor sit</p>
</div>
</div></div><!–./1st container–>
The best I could do was put the two class names together in line 6 … className==”pri-question”, “question”) which resulted in [url]http://www.fuzzy-art.com/drop/
Many thanks
Cliff
PS it would be a bonus to get it all to expand all if javascript has been turned off in the browser.