Show/hide 'div' using JavaScript

前端 未结 14 833
伪装坚强ぢ
伪装坚强ぢ 2020-11-22 04:18

For a website I\'m doing, I want to load one div, and hide another, then have two buttons that will toggle views between the div using JavaScript.

This is my

14条回答
  •  时光说笑
    2020-11-22 04:34

    Set your HTML as

    
     
    

    And now set the javascript as

    function changeDiv()
      {
      document.getElementById('body').hidden = "hidden"; // hide body div tag
      document.getElementById('body1').hidden = ""; // show body1 div tag
      document.getElementById('body1').innerHTML = "If you can see this, JavaScript function worked"; 
      // display text if JavaScript worked
       }
    

提交回复
热议问题