Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Class notes

Class notes 4310702

Rating
-
Sold
-
Pages
17
Uploaded on
01-03-2025
Written in
2024/2025

Lecture notes of 17 pages for the course 4310702 at UoN (Javascript)

Institution
Course

Content preview

Javascript DOM Access and Manipulation
●​ DOM stands for Document Object Model.
●​ It is a powerful tool that allows you to interact with and manipulate the elements on a
web page.
●​ The Document part refers to the webpage you see in the browser.
●​ Specifically, the HTML Document which handles the structure of the page's content.
●​ This includes the text, images, links, and other elements that make up the page.
●​ Object means the elements like images, headers, and paragraphs are treated like objects.
●​ Each object has its properties (like id, class, style) and methods. Using these properties
and methods, you can manipulate the elements.
●​ The Model in DOM means it's a representation or copy of the HTML document as a
hierarchical tree.
●​ This tree includes all the elements. And it captures the parent-child relationships between
them.
●​ The DOM is always identical to the HTML document. Browsers ensure that they are in
sync. So if something changes in the HTML, the DOM changes too, and vice versa.

, ●​ At the top of the hierarchy is the Document object.
●​ It has only one child – the html element.
●​ The html element, also known as the root element, has two children, the head and body
elements.
●​ And each of them also have their own children elements.
●​ The parent-child relationship between the elements is what allows you to traverse or
move between and select them.


What You Can Do With the DOM
DOM manipulation allows developers to interact with the structure, style, and content of web
pages. The following are some of the things you can do with the DOM:
●​ Change and remove existing elements in the DOM.
●​ Create and add new elements to the page.
●​ Change the styles for elements.
●​ Add event listeners to the elements to make them interactive.


Accessing the DOM Elements
JavaScript provides multiple ways to access elements in the DOM.


document.getElementById()

Finds an element by its id. document.getElementById("demo") selects the <p> element with the
id demo.
<!DOCTYPE html>
<html lang="en">
<head>
<title>DOM</title>
</head>
<body>
<p id="demo">Hello, World!</p>
<script>
let element = document.getElementById("demo");

, console.log(element.innerText);
</script>
</body>
</html>



document.getElementsByClassName()

Finds elements by their class name.
Returns an HTMLCollection (array-like) of all elements with class "example".
Use elements[index] to access specific elements.


<!DOCTYPE html>
<html lang="en">
<head>
<title>DOM</title>
</head>
<body>
<p class="example">First paragraph</p>
<p class="example">Second paragraph</p>
<script>
let elements = document.getElementsByClassName("example");
console.log(elements[1].innerText);
</script>


</body>
</html>




document.getElementsByTagName()

Finds elements by their tag name.

Written for

Institution
Course

Document information

Uploaded on
March 1, 2025
Number of pages
17
Written in
2024/2025
Type
Class notes
Professor(s)
W
Contains
All classes

Subjects

$8.49
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller
Seller avatar
smocharingoz

Also available in package deal

Get to know the seller

Seller avatar
smocharingoz
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
1 year
Number of followers
0
Documents
17
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions