{"id":26871241,"url":"https://github.com/codeadamca/javascript-dom","last_synced_at":"2025-03-31T07:18:52.438Z","repository":{"id":46327812,"uuid":"332280423","full_name":"codeadamca/javascript-dom","owner":"codeadamca","description":"A basic example of using JavaScript to make changes to a webpage using the DOM.","archived":false,"fork":false,"pushed_at":"2025-01-26T22:03:13.000Z","size":145,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-26T23:17:52.693Z","etag":null,"topics":["dom","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-23T18:28:25.000Z","updated_at":"2025-01-26T22:03:17.000Z","dependencies_parsed_at":"2025-01-26T23:27:54.024Z","dependency_job_id":null,"html_url":"https://github.com/codeadamca/javascript-dom","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-dom","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codeadamca%2Fjavascript-dom/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codeadamca%2Fjavascript-dom/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codeadamca%2Fjavascript-dom/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/codeadamca","download_url":"https://codeload.github.com/codeadamca/javascript-dom/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":["dom","javascript","learning-code"],"created_at":"2025-03-31T07:18:51.869Z","updated_at":"2025-03-31T07:18:52.427Z","avatar_url":"https://github.com/codeadamca.png","language":"HTML","readme":"# A Basic Introduction to JavaScript and the DOM\n\nWhen a browser renders a webpage from an HTML document, the browser creats a DOM (Document Object Model). This DOM can be use by JavaScript to add and/or manipulate elements in the document.\n\n## Example DOM\n\nFor example, the following HTML:\n\n```html\n\u003c!doctype html\u003e\n\u003chtml\u003e\n\u003chead\u003e\n    \u003ctitle\u003eThe JavaScript DOM\u003c/title\u003e\n\u003c/head\u003e\n\u003cbody\u003e\n\n    \u003ch1\u003eThe JavaScript DOM\u003c/h1\u003e\n\n    \u003cp\u003eMauris convallis dictum odio. Quisque euismod finibus.\u003c/p\u003e\n\n    \u003ca href=\"https://codeadam.ca\"\u003ecodeadam.ca\u003c/a\u003e\n    \n\u003c/body\u003e\n\u003c/html\u003e\n```\n\nWould have the following DOM:\n\n![DOM Chart](_readme/dom-chart.png)\n\n## Referencing Elements\n\nThe easiest method of referencing an element in the DOM is by giving the elements IDs:\n\n```html\n\u003c!doctype html\u003e\n\u003chtml\u003e\n\u003chead\u003e\n    \u003ctitle\u003eThe JavaScript DOM\u003c/title\u003e\n\u003c/head\u003e\n\u003cbody\u003e\n\n    \u003ch1 id=\"heading\"\u003eThe JavaScript DOM\u003c/h1\u003e\n\n    \u003cp id=\"paragraph\"\u003eMauris convallis dictum odio. Quisque euismod finibus.\u003c/p\u003e\n\n    \u003ca id=\"link\" href=\"https://codeadam.ca\"\u003ecodeadam.ca\u003c/a\u003e\n    \n\u003c/body\u003e\n\u003c/html\u003e\n```\n\nTo reference the heading we would use the `document.getElementById('heading')`. We can then use a DOM element to change the properties of the element. For example, to change the heading to red we would use the following JavaScript:\n\n```javascript\ndocument.getElementById('heading').style.color = \"red\";\n```\n\nTo change the `href` value of the link we would use the following JavaScript:\n\n```javascript\ndocument.getElementById('link').href = \"https://codeadam.ca/learning/javascript-dom.html\";\n```\n\n## Trying It Out\n\nCreate a new HTML document, add a heading, some images, and some paragraphs. Use [Lipsum](https://lipsum.com/) for some quick paragraph content. Add some JavaScript to the HTML document that will complete the following objectives:\n\n1. Change the text colour of the `h1` element.\n2. Change the text of the first `p` element.\n3. Change the border colour of one of the `img` elements.\n4. Change the background colour of the `body` element.\n\n\u003e Full tutorial URL:   \n\u003e https://codeadam.ca/learning/javascript-dom.html\n\n***\n\n## Repo Resources\n\n* [Visual Studio Code](https://code.visualstudio.com/)\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","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodeadamca%2Fjavascript-dom","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcodeadamca%2Fjavascript-dom","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodeadamca%2Fjavascript-dom/lists"}