Here is the link https://jsfiddle.net/0mrqgoxf/

$(function(){ var bt = $('#bt'); bt.click(function(){ var text = $('#text'); text.toggle(1000); }); }); 

I would like to replace the text from "Hide item" with "Show item" when the item is hidden / shown. I tried both if-else, and .text () method, and .toggle () - It does not work. I ask to help, as I only study jQuery. Thank you in advance.

    1 answer 1

     $(function(){ const text = $('#text'); const bt = $('#bt') let active = false; bt.click(function(){ text.toggle(1000); active = !active; if(active) bt.text('Показать элемент'); else bt.text('Скрыть элемент'); }); }); 
     <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <button id="bt">Скрыть элемент</button> <div id="text">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Architecto consequatur dignissimos sint commodi quod eum.</div> 

    • Everything works, thank you! - Ivan Zadvornov