Add Class to Object on Page Load

后端 未结 2 1600
暗喜
暗喜 2020-12-16 04:49

Basically I want to make this:

  • About
  • Into this when the page loads:

    &l         
    
    
            
    相关标签:
    2条回答
    • 2020-12-16 05:08

      I would recommend using jQuery with this function:

      $(document).ready(function(){
       $('#about').addClass('expand');
      });
      

      This will add the expand class to an element with id of about when the dom is ready on page load.

      0 讨论(0)
    • 2020-12-16 05:15

      This should work:

      window.onload = function() {
        document.getElementById('about').className = 'expand';
      };
      

      Or if you're using jQuery:

      $(function() {
        $('#about').addClass('expand');
      });
      
      0 讨论(0)
    提交回复
    热议问题