Hello, friends! Please, whom not laziness, tell me how to change the visibility of a block by a unique identifier. I tried to solve with different approaches, to change the display style in place, to post an attribute to an element according to ai-di, it does not work. Maybe because the pieces are in different files.

//index.php <div id="ar_home_page" class="page_content"> <? include'includes/ar_home.php'; ?> </div> <div id="market_page" class="page_content" style="display:none"> <? include'includes/market.php'; ?> </div> //includes/nav.php <li><a href="#" onclick=" магия, изменяющая видимость блоков: #ar_home_page скрыть, а #market_page показать ">Магазин</a></li> 

Thanks for answers! Sincerely, Yura.

  • Your question is not completely clear, you can describe in more detail what you want to achieve. - quaresma89
  • Hi, quaresma89 - Yuri Morozov
  • Hi, quaresma89 I, according to my scenario, should remain on this page for now. There is a link in the menu (visible on the code), I need to hide the first div by clicking on it and show the second div (the second one is hidden by default in the style.css file). - Yuri Morozov

1 answer 1

My advice: read about the server part of the code, the client. At the time when the page is generated, the server code (PCP) is already running. Those. the LoadMarket () function will work before clicking on the link. Hence, the need to implement the algorithm given in the question disappears. Summarizing: everything we write in the server code, in this case, in php work even BEFORE user interaction. That is, using php we create a page as if we wrote it "manually", without using a server. We create markup on it, with some kind of functionality and interaction between elements at the client level. That is, if we in php want to create a link, upon clicking on which we would fall out a window with a message variable, for example equal to Hello World , then we would use the following code:

 $someVar = 'Hello World'; echo "<a href='javascript:alert(\"$someVar\")'>Click me</a>"`. 

Due to the lack of meaning in this, as such, the client should deal with these tasks: <li><a href="#" onclick="$('div.page_content').toggle()">Магазин</a></li>


Or, we form a page starting from the initial parameters (in this case in the request)

 //php $mode = $_GET('mode'); //Получаем параметр mode из ссылки if($mode == 'market'){//проверяем его значение <? <div id="content_page" class="page_content"> <? include'includes/market.php'; ?> </div> ?> }else{ <? <div id="content_page" class="page_content"> <? include'includes/ar_home.php'; ?> </div> ?> 

And we get access to the store from the link type .../index.php?mode=market


  • Thanks, the crutch is fine for me. But what, in my case, some condition? Is it possible to write the second crutch in the navigator to balance: <a onclick="<?$click=true?> "> - Yuri Morozov
  • one
    @YuriMorozov, corrected the answer. As it turned out, the problem here is even deeper than just a crutch solution. And if you understand it, it will be much easier to implement such things. - SLy_huh
  • Oh yeah! Here I am, right now, SLy_huh gave me the right answer. I just forgot to think about it - to distinguish the server from the client. - Yuri Morozov
  • Thanks SLy_huh, everything worked out. The main thing that I understand is how it is done. - Yuri Morozov
  • @YuriMorozov, well, actually these are the very goals that we pursued, you can mark the question closed, and the answer is correct ' 3' - SLy_huh