Demo: Toggle a Div with One Button

← tutorial on show hide layer Demo using two buttons →

JavaScript Top ↑

const button=document.getElementById('bt1');
const box=document.getElementById('sub3');
button.addEventListener('click',()=>{
  box.hidden=!box.hidden;
  const visible=!box.hidden;
  button.textContent=visible?'Hide Layer':'Show Layer';
  button.setAttribute('aria-expanded',String(visible));
});

HTML Top ↑

<button type="button" id="bt1" aria-expanded="false">Show Layer</button>
<div id="sub3" hidden>Message Box</div>

Style Top ↑

#sub3{background-color:#f1f1f1;width:280px;padding:10px;color:#000;border:2px dashed #0000cc;}



Subscribe to our YouTube Channel here



plus2net.com










✖
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
© 2000-2026 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer