使用JavaScript在HTML中显示或隐藏节



在我的HTML文件中有一个类似于以下的部分元素:

<section id="analysisData" hidden>
..
</section>

如何使用JavaScript切换它的可见性?我试过这样的方法让它可见:

document.getElementById('analysisData').style.visibility='visible';

不幸的是,这不起作用吗?知道吗?

使用纯JS

document.getElementById('analysisData').style.display='block'; //to show
document.getElementById('analysisData').style.display='none'; //to hide

使用jQuery

$('#analysisData').toggle()

最新更新