Have a menu! Diva appears and closes, but I need to have a PRIORTHE DEEP CLOSE UP WITH A CLICK!

function divBlock(gett){ if(gett.style.display == "block"){ gett.style.display = "none"; }else{ gett.style.display = "block"; } } 

Update

 <?php function CategTableQuery(){ $query=mysql_query("SELECT * FROM `catgName`"); $q=mysql_query("SELECT * FROM `catg`"); while($row=mysql_fetch_array($query)){ $r=mysql_fetch_array($q); ?> <div onclick="divBlock(blockCatg_<?php echo $r["id"];?>);" class="b1"> <p id="PcatgName" class="bl"><?php echo $row["name"]; ?></p> </div> <?php } } function blockCatg($nameCatg,$num){ $query=mysql_query("SELECT * FROM `catg` WHERE ctg='$nameCatg'"); echo'<ul id="blockCatg_'.$num.'" class="b2" style="display:none;">'; while($row=mysql_fetch_array($query)){ ?> <li id="catg_<?php echo $row["id"];?>" class="CatgStyle" > <a href="index.php?id=<?php echo $row["id"]; ?>" id="PcatgName" ><?php echo $row["name"]; ?></a> </li> <?php } echo'</ul>'; } ?> <div id="search"> <?php CategTableQuery(); blockCatg(cw,1); blockCatg(ndj,2); blockCatg(car,3); blockCatg(job,4); blockCatg(anim,5); blockCatg(hom,6); blockCatg(elec,7); blockCatg(bis,8); blockCatg(mod,9); blockCatg(hob,10); blockCatg(exc,11); blockCatg(giv,12); ?></div><?php ?> <script> /* var id_menu = new Array('blockCatg_1','blockCatg_2','blockCatg_3,blockCatg_4','blockCatg_5','blockCatg_6,blockCatg_7','blockCatg_8','blockCatg_9,blockCatg_10','blockCatg_11','blockCatg_12'); startList = function allclose() { for (i=0; i < id_menu.length; i++){ document.getElementById(id_menu[i]).style.display = "none"; } } */ function divBlock(gett){ /* for (i=0; i < gett.length; i++){ if (id != gett[i]){ document.getElementById(id_menu[i]).style.display = "none"; } }*/ // var blockCatg = document.getElementById("blockCatg"); gett.previousElementSibling.style.display = "none"; if(gett.style.display == "block"){ gett.style.display = "none"; }else{ gett.style.display = "block"; } } </script> 

Closed due to the fact that it is necessary to reformulate the question so that it was possible to give an objectively correct answer by the participants HamSter , user207618, tutankhamun , aleksandr barakin , rjhdby 5 Oct '16 at 18:14 .

The question gives rise to endless debates and discussions based not on knowledge, but on opinions. To get an answer, rephrase your question so that it can be given an unambiguously correct answer, or delete the question altogether. If the question can be reformulated according to the rules set out in the certificate , edit it .

  • "Div closes", did anyone understand what it was about? - MasterAlex
  • As I understood it is necessary to have an accordion - soledar10
  • Well, not clear - the sofa is moving apart, it is going in the morning. - 0xdb
  • @Novichek Can you formulate a specific question? What do you see the complexity of the solution? - 0xdb
  • friends here is a link where I test - Novichek

2 answers 2

My telepathic abilities suggest that maybe you just need to assign a single class to the divs, and when you click on the menu, first close all the divs with this class, and then open the right one.

More without a code, I will not answer.

    if necessary to close the div at the same level, then maybe you wanted to do:

     gett.previousElementSibling.style.display = "none"; 
    • function divBlock (gett) {/ * for (i = 0; i <gett.length; i ++) {if (id! = gett [i]) {document.getElementById (id_menu [i]). style.display = "none "; }} * / // var blockCatg = document.getElementById ("blockCatg"); gett.previousElementSibling.style.display = "none"; if (gett.style.display == "block") {gett.style.display = "none"; } else {gett.style.display = "block"; }} - Novichek
    • does not work ((( - Novichek
    • one
      I think the problem is that your question is not very precisely worded. Describe a little more in detail what you want to do, show in detail what you have (markup of blocks for example) and what exactly does not work. - Vyacheslav Danshin