{"id":451,"date":"2013-06-11T09:23:57","date_gmt":"2013-06-11T09:23:57","guid":{"rendered":"http:\/\/putridparrot.com\/blog\/?p=451"},"modified":"2013-06-12T07:41:26","modified_gmt":"2013-06-12T07:41:26","slug":"javascript-refresher-using-in-html","status":"publish","type":"post","link":"https:\/\/putridparrot.com\/blog\/javascript-refresher-using-in-html\/","title":{"rendered":"JavaScript Refresher &#8211; Using JavaScript in HTML"},"content":{"rendered":"<p><strong>How to use JavaScript in an HTML file<\/strong><\/p>\n<p>JavaScript is a dynamic loosely typed language which is now the lingua franca of the browser now.<\/p>\n<p>We can add JavaScript to a web page as inline, embedded or in an external .js file. For example<\/p>\n<p><strong>Inline<\/strong><\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n&lt;input type=&quot;button&quot; value=&quot;Click Me!&quot; onClick=&quot;alert('Clicked');&quot; \/&gt;\r\n<\/pre>\n<p>In the above the inline JavaScript will display an alter in response to the button being clicked.<\/p>\n<p><strong>Embedded<\/strong><\/p>\n<p>The same code as above but with the JavaScript embedded would look more like<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;script&gt;\r\nfunction clicked() {\r\n   alert('Clicked');\r\n}\r\n&lt;\/script&gt;\r\n\r\n&lt;input type=&quot;button&quot; value=&quot;Click Me!&quot; onClick=&quot;clicked();&quot; \/&gt;\r\n<\/pre>\n<p>I&#8217;ve removed superfluous code but the usual place to put the script is in the <head> section.<\/p>\n<p><strong>External File<\/strong><\/p>\n<p>If we have a file name (for example) scripts.js then we&#8217;d place the scripting code in that file as below<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nfunction clicked() {\r\n   alert('Clicked');\r\n}\r\n<\/pre>\n<p>and in the <head> of the HTML file we&#8217;d have the reference to the script<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;script type=&quot;text\/javascript&quot; language=&quot;javascript&quot; src=&quot;scripts.js&quot;&gt;&lt;\/script&gt;\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>How to use JavaScript in an HTML file JavaScript is a dynamic loosely typed language which is now the lingua franca of the browser now. We can add JavaScript to a web page as inline, embedded or in an external .js file. For example Inline &lt;input type=&quot;button&quot; value=&quot;Click Me!&quot; onClick=&quot;alert(&#8216;Clicked&#8217;);&quot; \/&gt; In the above the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[45],"tags":[],"class_list":["post-451","post","type-post","status-publish","format-standard","hentry","category-javascript"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/451","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/comments?post=451"}],"version-history":[{"count":8,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/451\/revisions"}],"predecessor-version":[{"id":465,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/451\/revisions\/465"}],"wp:attachment":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/media?parent=451"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/categories?post=451"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/tags?post=451"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}