Surely, many used the functionality to display and hide certain content through Bootstrap Collapse . So I use it, everything is successful, but I have some shortcomings that I wanted to remove. There is the following code:
<input id="btnShowHideDeletedLft" onclick="changeTextBtnDeletedLft()" type="button" class="btn btn-info" data-toggle="collapse" data-target="#tblDeletedLft" value="Посмотреть удаленные" /> <div id="tblDeletedLft" class="collapse" style="margin-top: 10px;"> @* тут мой контент - небольшая таблица *@ </div> This code block successfully fulfills. But, there is also JavaScript , in which the text of my button changes, here it is:
function changeTextBtnDeletedLft() { var elem = document.getElementById("btnShowHideDeletedLft"); //elem.disabled = true; if (elem.value === 'Посмотреть удаленные') { elem.value = 'Скрыть удаленные'; } else { elem.value = 'Посмотреть удаленные'; } //setTimeout(function() { elem.disabled = false; }, 500); } This code also works, but alas, it does not work the way I would like, it is the problem that lies in it, namely: if you quickly double-click a button, the text in it changes twice, and the table is displayed (hidden) once. As a result, the test in the button will be View deleted and the table will already be displayed, or vice versa, that is, there will be a mismatch of the label in the button and the content.
After that, the thought came to me, and what if the disable button is half a second after the click, the table will appear in time for this time, and the user will not click twice in a row!
If you use commented code in JavaScript , then Collapse stops working. That is, the display and hide the table does not occur. The text in the button changes, it disappears, but the display and hide doesn't work.
Of course, you can write on the View / Hide deleted button and you will not need to change the text, which means that timeouts are not needed, but I would like to use Feng Shui to disable the button and change the text in it and display / hide the content. How to do it?