Skip to content Skip to sidebar Skip to footer

Script Tag Works Inside The Body But Doesn't Work Outside

Hi I made a webpage that uses modal to display the output, I came in a scenario where in I put my script tags inside the body and the program work out fin, however when I was clean

Solution 1:

Try to write you code in $(document).ready() so that you DOM is ready to use, otherwise it may not work

Try it like,

$(function(){
   // your js code
});

Solution 2:

Just leave the script-tag within the body and everything will work fine.

If you want to clean up the HTML-file put your Javascript code into an external JS-file and load it at the end of your body with:

<scripttype="text/javascript"src="main.js"></script></body>

Post a Comment for "Script Tag Works Inside The Body But Doesn't Work Outside"