Skip to content

Instantly share code, notes, and snippets.

@pozitron57
Created February 12, 2023 22:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pozitron57/32d82fbd8cc3ee3973a8e3e48cce8427 to your computer and use it in GitHub Desktop.
Save pozitron57/32d82fbd8cc3ee3973a8e3e48cce8427 to your computer and use it in GitHub Desktop.
Change button text onclick and show/hide element.
<script>
function toggleHidden() {
document.getElementById("solution").classList.toggle('hidden');
if ( document.getElementById("solution").classList.contains('hidden') ) {
document.querySelector('#btn').innerText = 'Показать решение';
} else {
document.querySelector('#btn').innerText = 'Скрыть решение';
}
}
</script>
<style>
.hidden { display: none;}
</style>
<p> Текст задачи. </p>
<p class="hidden" id="solution"> Решение задачи. </p>
<button onclick="toggleHidden()" id='btn'> Показать решение. </button>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment