Demo: Show and Hide Two Div Layers

← tutorial on show hide layer

JavaScript Top ↑

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

HTML Top ↑

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

Style Top ↑

#sub3,#sub4{background-color:#f1f1f1;width:280px;padding:10px;color:#000;border:2px dashed #0000cc;margin-top:1rem;}



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