HTML JS

HOW TO INCLUDE JAVASCRIPT IN HTML

LOAD AN EXTERNAL JAVASCRIPT FILE <script src="SCRIPT.JS"></script> <script src="HTTP://SITE.COM/ SCRIPT.JS"></script>

EXTERNAL JAVASCRIPT

01

<p>Paragraph/p>   <script> PLACE JAVASCRIPT IN <SCRIPT> TAGS, WITHIN THE HTML DOCUMENT. </script>   <p>Another Paragraph/p>

INTERNAL JAVASCRIPT

02

DIRECTLY ADD JAVASCRIPT TO HTML ELEMENTS <p onclick="FUNCTION()">Click</p> <p onmouseover="FUNCTION()">   Hover </p>

INLINE JAVASCRIPT

03

<script> ERROR - VAR FOO IS NOT DEFINED alert(foo); </script>

LOADING ORDER MATTERS

04

<p>Paragraph</p> <script> THIS SHOULD BE ON TOP var foo = "bar"; </script>