{"id":273,"date":"2021-06-07T16:31:37","date_gmt":"2021-06-07T15:31:37","guid":{"rendered":"https:\/\/blogs.glowscotland.org.uk\/sh\/ahscomputinghtml\/?page_id=273"},"modified":"2021-06-07T22:16:20","modified_gmt":"2021-06-07T21:16:20","slug":"where-to-store-javascript","status":"publish","type":"page","link":"https:\/\/blogs.glowscotland.org.uk\/sh\/ahscomputinghtml\/javascript\/where-to-store-javascript\/","title":{"rendered":"Where to store JavaScript"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" class=\"alignright wp-image-197\" src=\"https:\/\/glow-prod-sh.s3.eu-west-1.amazonaws.com\/sh\/public\/ahscomputinghtml\/uploads\/sites\/3275\/2021\/06\/05211153\/sqa-h-150x150.png?X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&#038;X-Amz-Security-Token=IQoJb3JpZ2luX2VjEE8aCWV1LXdlc3QtMSJHMEUCIQDxM6YiQF4yBmDtwowOJC6b0jigPQSzmCDDla3pVBEergIgd%2Ffi0R0XBZ1L5xyadjv6O9UY5bu1ij51I7HVNFl9wxwquAUIGBAFGgwyNzM1NzAxOTU0MzMiDMyrKtx%2FbKagKA8HGiqVBR%2FPei8m5kWAVB2X0nEDS5gp8EdxqcqrBLskmcQan6kHrsejKotuoe174dOd51ZpYrGX%2Fp2mMA7a0bAUetkMWYbJGx6GKK6lI4Id3oPdJlcMIkIfz1EzwTR6IitURBtHbfGmuSULSq7j7TIKEjF0gXsvRlqpmD6%2Fx6tgea1GlDur0AdaxsJpkBlvK0jXy3b5%2FAvlqIFT%2F3kL7W2N0Rk5BNoADSgEnAHJPCmFiinF8mCYW3Cp%2FBFZfYcFyNNcdWCdko0i6mAYDlqSN09nqXTpeiYgGH7NZgixaAuXcYvY0gZ2%2Fc5x02Vu7BIH5LdoXMhfAATm9MzlLfyTHF25DqXXDuoQe9Ex361M6obJh84c%2FDiHJCNTlLM17iNDg2Y%2BC2Ff4C4xXyN6qR49gTUk2tSsrRKtpEmikEyD7KF%2B3P8KNoKcRXpIAO%2B7kf6FpU8Ax6ezJoFBANOWAjwQuJ8yxXt7sJMkApCCaHpdj7Ss2T6oyR5S9KQP0ryOZVJ1R8JoWDN8Tlm67FqKqcAM7nd7AUmeAHcMtwHd%2FizNt7bnzljpE35dDs32f1hsM%2FigyoOAj6hRLsej61WaJySmYmsTHuu%2BytEVJw0TuFToLMvcoAYqKReMMroRmu1Dz6784BjEER65S1noS0W4NwczeKdhm1nAS6ubM%2BLjOi8SWw67NOWaMOUDUra3EpHOsi%2FLlwhbtJswh7TPJAEubpojAUcSBHU6ruGsZmBK9oJ%2F31kvp4z6iyV%2Fwlu85AS5%2BEV1KF0s1yuXz1b7JmgSlA4qk8ZwLQ9aKY%2B%2B981elKc8LvvwKnbJ0baOYXzcvnYVDdSKeOohDVd6w3hsGZoLJ3jy1saPjSzsjliuc5g3M%2FIMQ5DA2%2BsfDPkaxu%2B%2FQe8wspGXzwY6sQGbk%2BWiM5%2Ff%2B172cLYKeWgeM6VB%2BopX0%2Bbdhu74zBwjtEZ86%2BySIw1XhJWPicF2nUMkZK2afQj7sR3mBzEyXqFC6yAMmKmnyKg%2B9o64KuoXH6BIL6NJ2RIMx9kJ%2FRquyXLloQQAbr2idsvomYUXehzfAZORzrKFod4P5a2A55bi%2BlokZBOm1g%2BNAu%2BKqpWFjWmYXF6fw4Ww8KWCpnX3yWvW1GuOCp9o9zpMRaVTAL%2Fz%2F0A%3D&#038;X-Amz-Algorithm=AWS4-HMAC-SHA256&#038;X-Amz-Credential=ASIAT7MQN47UUQAL7HMR%2F20260420%2Feu-west-1%2Fs3%2Faws4_request&#038;X-Amz-Date=20260420T064418Z&#038;X-Amz-SignedHeaders=host&#038;X-Amz-Expires=900&#038;X-Amz-Signature=c8bce43595897aebd465327dd794b21390e3bccb23a923468dc68e4144b5c87a\" alt=\"\" width=\"100\" height=\"97\" \/>As with CSS, JavaScript can be placed inside HTML elements, within an HTML file, or in a separate file.<\/p>\n<p>&nbsp;<\/p>\n<h1>Inline JavaScript<\/h1>\n<p>The JavaScript code to respond to an event is written inside the HTMl element.<\/p>\n<p>This is only suitable for very simple scripts.<\/p>\n<pre class=\"brush: xml; title: HTML body; notranslate\" title=\"HTML body\">\r\n&lt;button onclick=&quot;alert('You clicked me!')&quot;&gt;Click Me&lt;\/button&gt;\r\n<\/pre>\n<h1>Internal JavaScript Code<\/h1>\n<p>All JavaScript functions are written in a &lt;script&gt; block, often placed inside the &lt;head&gt; block for maintainability. A script block can contain multiple functions.<\/p>\n<p>Events then call these functions.<\/p>\n<p>Note: Program\/Text editors will use syntax highlighting for HTML, leaving the &lt;script&gt; blocks unformatted &#8211; and harder to debug.<\/p>\n<pre class=\"brush: xml; title: HTML head; notranslate\" title=\"HTML head\">&lt;script&gt;\r\n    function showCopyright() { \r\n        alert(&quot;This page is copyright A Person 2021&quot;); \r\n    }\r\n&lt;script&gt;<\/pre>\n<pre class=\"brush: xml; title: HTML body; notranslate\" title=\"HTML body\">&lt;button onclick=&quot;showCopyright()&quot;&gt;Copyright&lt;\/button&gt;<\/pre>\n<h1>External JavaScript File<\/h1>\n<p>If you will use the same scripts across several pages, then save them in a separate file &#8211; <strong>myscripts.js<\/strong><\/p>\n<p>Add a link to the file in the &lt;head&gt; of the HTML:<\/p>\n<pre class=\"brush: jscript; title: myscripts.js; notranslate\" title=\"myscripts.js\">\r\nfunction showCopyright() { \r\n    alert(&quot;This page is copyright A Person 2021&quot;); \r\n}<\/pre>\n<pre class=\"brush: xml; title: HTML head; notranslate\" title=\"HTML head\">&lt;script src=&quot;myscripts.js&quot;&gt;&lt;\/script&gt;<\/pre>\n<pre class=\"brush: xml; title: HTML body; notranslate\" title=\"HTML body\">&lt;button onclick=&quot;showCopyright()&quot;&gt;Copyright&lt;\/button&gt;<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>As with CSS, JavaScript can be placed inside HTML elements, within an HTML file, or in a separate file. &nbsp; Inline JavaScript The JavaScript code to respond to an event is written inside the HTMl element. This is only suitable for very simple scripts. &lt;button onclick=&quot;alert(&#8216;You clicked me!&#8217;)&quot;&gt;Click Me&lt;\/button&gt; Internal JavaScript Code All JavaScript functions are written in a &lt;script&gt; block, often placed inside the &lt;head&gt; block for maintainability. A<\/p>\n<p><a class=\"more-link\" href=\"https:\/\/blogs.glowscotland.org.uk\/sh\/ahscomputinghtml\/javascript\/where-to-store-javascript\/\">Read More<\/a><\/p>\n","protected":false},"author":7,"featured_media":0,"parent":259,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-273","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/blogs.glowscotland.org.uk\/sh\/ahscomputinghtml\/wp-json\/wp\/v2\/pages\/273","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.glowscotland.org.uk\/sh\/ahscomputinghtml\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/blogs.glowscotland.org.uk\/sh\/ahscomputinghtml\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.glowscotland.org.uk\/sh\/ahscomputinghtml\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.glowscotland.org.uk\/sh\/ahscomputinghtml\/wp-json\/wp\/v2\/comments?post=273"}],"version-history":[{"count":14,"href":"https:\/\/blogs.glowscotland.org.uk\/sh\/ahscomputinghtml\/wp-json\/wp\/v2\/pages\/273\/revisions"}],"predecessor-version":[{"id":294,"href":"https:\/\/blogs.glowscotland.org.uk\/sh\/ahscomputinghtml\/wp-json\/wp\/v2\/pages\/273\/revisions\/294"}],"up":[{"embeddable":true,"href":"https:\/\/blogs.glowscotland.org.uk\/sh\/ahscomputinghtml\/wp-json\/wp\/v2\/pages\/259"}],"wp:attachment":[{"href":"https:\/\/blogs.glowscotland.org.uk\/sh\/ahscomputinghtml\/wp-json\/wp\/v2\/media?parent=273"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}