How can I detect DOM ready and add a class without jQuery?

后端 未结 8 1359
独厮守ぢ
独厮守ぢ 2020-11-28 06:04

I want to rewrite this line without using jQuery so it can be applied quicker (and before the downloading of the jQuery library). The line is...

$(document).         


        
8条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-28 06:52

    window.onload = function() {
       var elmt =  document.getElementsByTagName('body');
       if(elmt){
          elmt[0].className = 'javascript';
       }
    }
    

    That should do it.

    EDIT: Updated to get element by tag name not ID.

提交回复
热议问题