[removed] Hiding and Showing div tag with a toggle button

前端 未结 4 2073
鱼传尺愫
鱼传尺愫 2020-12-11 23:46

I\'ll get right to it:

What I need to do is hide a particular div with the press of a button, and it\'s supposed to be a toggle, so basically: Press once to hide, pr

4条回答
  •  情书的邮戳
    2020-12-12 00:09

    You can make use an onclick method. Have your HTML as:

    Show/hide

    I want to hide this by pressing the button above

    And have the following JavaScript:

    function toggle_visibility(id) 
    {
        var e = document.getElementById(id);
        if (e.style.display == 'block' || e.style.display=='')
        {
            e.style.display = 'none';
        }
        else 
        {
            e.style.display = 'block';
        }
    }
    

    DEMO

提交回复
热议问题