You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Week1/LESSONPLAN.md
+53-2Lines changed: 53 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -18,18 +18,69 @@ The purpose of this class is to introduce to the student:
18
18
19
19
FIRST HALF (12.00 - 13.30)
20
20
21
-
## 1. How a webpage is made up of objects (DOM)
21
+
## 1. Document Object Model (DOM)
22
22
23
23
### Explanation
24
+
The [Document Object Model (DOM)](https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model/Introduction) is an _object-oriented representation_ of a web page(HTML document) which the web browsers make available to JavaScript for manipulation. Inside a JavaScript file, we can access the DOM through a global object called `document` or `window.document`.
25
+
26
+
**It is not a programming language but without it JavaScript would not have any knowledge of our web page/HTML document.**

25
43
### Exercise
26
44
### Essence
27
45
28
46
29
-
## 2. How JavaScript can be used to manipulate those objects (DOM manipulation)
47
+
## 2. DOM manipulation
30
48
### Explanation
31
49
### Example
50
+
1. Finding DOM elements in HTML page
51
+
52
+
-`document.getElementById(id)` - Find an element by element id
53
+
-`document.getElementsByTagName(name)` - Find elements by tag name
54
+
-`document.getElementsByClassName(name)` - Find elements by class name
55
+
56
+
2. Adding and Deleting elements in HTML page
57
+
58
+
-`document.createElement(element)` - Create a new HTML element
59
+
-`document.removeChild(element)` - Remove an HTML element
60
+
-`document.appendChild(element)` - Add an HTML element
61
+
62
+
3. Changing existing HTML elements
63
+
64
+
-`element.innerHTML` - Change the content/layout of the element
65
+
-`element.innerText` - Change just the text of the element
66
+
-`element.setAttribute(attribute, value)` - Set/Change attribute of an element
67
+
68
+
* Note: `getElementsByTagName` and `getElementsByClassName` returns a list of all matched elements. However, this is not the usual JavaScript array but an HTMLCollection List. A detailed list of APIs available on the DOM can be found [here](https://developer.mozilla.org/en-US/docs/Web/API/Document).
32
69
### Exercise
70
+
1. Create an HTML form element
71
+
2. Create an HTML input(type text) element and set its placeholder as "First Name"
72
+
3. Create another HTML input(type text) element and set its placeholder as "Last Name"
73
+
4. Add both these elements to the form element
74
+
5. Create a button element and add these properties to it:
0 commit comments