So. There is such a div block with an identifier and a property. Inside there is info that you need to hide and show by flasher (by clicking on the link):

<div id="methodCaesar" style="display:none"> 

There is such a link:

 <a id="Caesar" href="" onclick="show('methodCaesar')">Шифр цезаря</a> 

And there is a JS code:

 function show(id) { var div = document.getElementById(id) if(div.style.display == '') div.style.display = 'none' else div.style.display = '' } 

The question is: what the hell is not working? And it does not work strange. I load the page, click on the button, and, if the alert is placed at the beginning of the script, the method will easily display information about the method passed in the parameter. Then, a div block with methodCaesar ID will appear. And then disappear again! If you go to the code inspector, then you can see that the DOM is updated 2 times (but the alert is displayed only 1 time, that is, the script is still executed 1 time). In addition, if you write in the console show ("methodCaesar"), then everything works fine as planned. I use the Chrome browser. And I want to work on chrome ... God knows what, completely broke my head, tell me, please, what am I doing wrong?

    2 answers 2

    Try to put # in href = "#"

     <a id="Caesar" href="#" onclick="show('methodCaesar')">Шифр цезаря</a> 
    • Thank you very much! Earned, of course. And so he, apparently, simply reloaded the current page? - VostokSisters

    Nothing unusual! When you click on a link, the page is updated and the result disappears. Try using a different text element instead of a link.