What's the difference between putting script in head and body?

后端 未结 9 974
花落未央
花落未央 2020-12-04 12:15

I was getting a problem .


  

        
9条回答
  •  萌比男神i
    2020-12-04 12:42

    It's simple, JavaScript will go from up-down, unless you tell it to do something else. By the time it reaches the li elements, the JavaScript code has already been completed.

    If you want to keep it in the head however, you could use the document.ready function and it will load only after the HTML it's loaded.

提交回复
热议问题