简体   繁体   中英

Show or hide section in HTML with JavaScript

In my HTML file there is an section-element like this:

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

How can I toggle it's visibility with JavaScript? I tried something like this to get it visible:

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

Unfortunately that does not work? Any idea?

With pure JS

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

With jQuery

$('#analysisData').toggle()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM