Let the DOM load. To do something in the DOM you have to Load it first. In your case You have to load the <div>
tag first. then you have something to modify. if you load the js first then that function is looking your HTML
to do what you asked to do, but when that time your HTML
is loading and your function cant find the HTML
. So you can put the script in the bottom of the page. inside <body>
tag then the function can access the <div>
Because DOM is already loaded the time you hit the script.