{"id":26871237,"url":"https://github.com/codeadamca/javascript-placement","last_synced_at":"2025-03-31T07:18:52.197Z","repository":{"id":46327422,"uuid":"329090213","full_name":"codeadamca/javascript-placement","owner":"codeadamca","description":"Three samples of JavaScript using inline, internal, and external JavaScript placement. ","archived":false,"fork":false,"pushed_at":"2025-01-26T22:03:42.000Z","size":15,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-26T23:17:56.245Z","etag":null,"topics":["javascript","learning-code"],"latest_commit_sha":null,"homepage":"","language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/codeadamca.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-01-12T19:26:55.000Z","updated_at":"2025-01-26T22:03:45.000Z","dependencies_parsed_at":"2025-01-26T23:27:53.914Z","dependency_job_id":null,"html_url":"https://github.com/codeadamca/javascript-placement","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codeadamca%2Fjavascript-placement","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codeadamca%2Fjavascript-placement/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codeadamca%2Fjavascript-placement/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codeadamca%2Fjavascript-placement/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/codeadamca","download_url":"https://codeload.github.com/codeadamca/javascript-placement/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246429486,"owners_count":20775809,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["javascript","learning-code"],"created_at":"2025-03-31T07:18:51.665Z","updated_at":"2025-03-31T07:18:52.179Z","avatar_url":"https://github.com/codeadamca.png","language":"HTML","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Including JavaScript in an HTML Document\n\nMuch like CSS, JavaScript can be placed into an HTML document using three different mthods:\n\n1. Inline\n2. Internal\n3. External\n\n## Inline\n\nJavaScript can be placed inside an HTML tag using an event attribute:\n\n- onclick\n- onmouseover\n- onsubmit\n\nOr inside an `href` attribute by prefixing it with `javascript:`.\n\nCreate a new HTML document, name is `inline.html`, add the standard HTML elements, and inside the `body` tag add the following code:\n\n```html\n\u003cinput type=\"button\" onclick=\"alert('This is inline JavaScript!');\" value=\"Click Me\"\u003e\n\n\u003cbr\u003e\u003cbr\u003e\n\n\u003ca href=\"javascript:alert('This is also inline JavaScript');void(0);\"\u003eClick Me\u003c/a\u003e\n```\n\nTest the HTML file using a browser. You should see an alert message by clicking either the button or link.\n\n## Internal\n\nJavaScript can be placed inside an HTML document by adding JavaScript code inside a `script` tag.\n\nCreate a new HTML document, name it `internal.html`, add the standard HTML elements, and inside the `body` tag add the following code:\n\n```html\n\u003cscript\u003e\n\ndocument.write(\"\u003ch1\u003eEmbedded JavaScript\u003c/h1\u003e\");\ndocument.write(\"\u003cp\u003eThis is embedded JavaScript!\u003c/p\u003e\");\n\n\u003c/script\u003e\n```\n\nTest the HTML file using a browser, the `body` section of the webpage should have an additional heading and paragraph.\n\n## External\n\nJavaScript can be placed inside an external JavaScript file. \n\nCreate a new JavaScript file and name it external.js. When placing JavaScript inside an external JavaScript file, you do not need to include `script` tags. Add the following code:\n\n```javascript\ndocument.write(\"\u003ch1\u003eExternal JavaScript\u003c/h1\u003e\");\ndocument.write(\"\u003cp\u003eThis content comes from an external JavaScript file!\u003c/p\u003e\");\n```\n\nNext, create an HTML file, name it external.html, add the standard HTML elements, and then add the following code to the `body` section:\n\n```html\n\u003cscript src=\"external.js\"\u003e\u003c/script\u003e\n```\n\nTest the file using a browser, the `body` section of the webpage should have an additional heading and paragraph.\n\n\u003e Full tutorial URL:  \n\u003e https://codeadam.ca/learning/javascript-placement.html\n\n***\n\n## Repo Resources\n\n* [Visual Studio Code](https://code.visualstudio.com/) or [Brackets](http://brackets.io/) (or any code editor)\n\n\u003cbr\u003e\n\u003ca href=\"https://codeadam.ca\"\u003e\n\u003cimg src=\"https://cdn.codeadam.ca/images@1.0.0/codeadam-logo-coloured-horizontal.png\" width=\"200\"\u003e\n\u003c/a\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodeadamca%2Fjavascript-placement","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcodeadamca%2Fjavascript-placement","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodeadamca%2Fjavascript-placement/lists"}