How to make a DIV visible and invisible with JavaScript

后端 未结 7 532
长情又很酷
长情又很酷 2020-12-02 11:50

Can you do something like

function showDiv()
{
    [DIV].visible = true;
    //or something
}
7条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-02 12:31

    You can use visibility or display but you have to apply changes to the div.style object and not the div object itself.

    var div = document.getElementById('div_id');
    
    // hide
    div.style.visibility = 'hidden';
    // OR
    div.style.display = 'none';
    
    // show
    div.style.visibility = 'visible';
    // OR
    div.style.display = 'block';
    

提交回复
热议问题