Se il Div che stai cercando di espandere è all'interno di altri Div che vengono crollati, dovrai espandere i Div del contenitore prima di espandere i Div per bambini affinché possano mostrare. Quindi devi almeno chiamare qualcosa come la funzione di attivatore nel codice di testa, ad esempio
window.onload = function() {
var hash = window.location.hash; // would be "#div1" or something
if(hash != "") {
toggle('CPNRE', this);/*this is an example the CPNRE value needs to be figured out*/
var id = hash.substr(1); // get rid of #
document.getElementById(id).style.display = 'block';
}
}
Questa è all'incirca l'idea, non una soluzione completa poiché è necessario capire il Div del contenitore per chiamare il bosco o qualche altra funzione per espandersi.
MODIFICARE
Un modo per raggiungere ciò che stai cercando di fare, in puro JS, sarebbe quello di fare quanto segue,
if(hash != "") {
var id = hash.substr(1); // get rid of #
document.getElementById(id).style.display = 'block';
document.getElementById(id).parentNode.parentNode.parentNode.style.display = 'block';
document.getElementById(id).parentNode.parentNode.style.display = 'block';
document.getElementById(id).parentNode.style.display = 'block';
document.getElementById(id).style.display='block';
}
Ma questo è legato al layout specifico che hai fornito nella tua domanda.
Una soluzione migliore, più generica, sarebbe quella di iterare i genitori fino a quando un genitore specifico non viene trovato in base al valore della classe, ad esempio
Html
/*add class value like faq-section to each div section */
<div class="FAA faq-section" id="faq1">
js
....
if(hash != "") {
var id= hash.substr(1);
var pNode = document.getElementById(id).parentNode;
var endLoop=false;
while(!endLoop){
if(pNode.className&&pNode.className.indexOf('faq-section')!=-1){
endLoop=true;
};
pNode.style.display='block';
pNode=pNode.parentNode;
}
document.getElementById(id).style.display='block';
}