-
Notifications
You must be signed in to change notification settings - Fork 2
v5 Week 11: DOM API
Reid Russom edited this page Oct 8, 2024
·
2 revisions
Week | Topic | Learning Objectives | Key Resources |
---|---|---|---|
11 | The DOM API | Students will be able to define the DOM and implement changes to parts of their portfolio project using DOM manipulation; use the DOM to handle form submission event on their portfolio project. | Week 11 Slides TBD |
- Tree-like representation of webpage contents
- Nodes have parent-child and sibling relationships
- Use CSS-style selectors and relationship properties to target nodes
- Examples:
div.display
,.display
,#container > .display
,firstElementChild
,lastElementChild
- Query selectors:
querySelector
,querySelectorAll
- Element creation:
createElement
- Appending elements:
appendChild
,insertBefore
- Removing elements:
removeChild
- Altering elements:
setAttribute
,textContent
,innerHTML
,style
,classList
- Actions that occur on a webpage (e.g., clicks, key presses)
- Three ways to handle events:
- Inline
onclick
attribute in HTML -
onclick
property in JavaScript -
addEventListener
in JavaScript (preferred method)
- Inline
- Event object:
addEventListener
callback function receives an event object with properties and methods - Attaching listeners to groups of nodes: use a loop or
forEach
to iterate through a NodeList
- Container for input elements
- Attributes:
action
(URL to send form data),method
(HTTP request method)
- Input elements:
<input>
with varioustype
attributes (e.g.,text
,email
,password
,number
,date
) - Labels:
<label>
associates a text label with an input element - Textarea:
<textarea>
multi-line text input - Select dropdown:
<select>
with<option>
elements - Radio buttons:
<input type="radio">
for mutually exclusive options - Checkboxes:
<input type="checkbox">
for multiple selections - Buttons:
<button>
for submitting, resetting, or custom actions
- Fieldset:
<fieldset>
groups related inputs - Legend:
<legend>
provides a caption for a fieldset
- Default browser styles may differ
- Text-based controls are easy to style with CSS
- Radio buttons and checkboxes require more complex styling techniques
- Some elements (e.g., date pickers) are difficult or impossible to style directly
Potential trouble spots for students:
- Understanding the relationship between the DOM and the original HTML source code
- Navigating the DOM tree and selecting the correct nodes using selectors and relationship properties
- Knowing when to use
innerHTML
vs.textContent
and understanding the security risks ofinnerHTML
- Recognizing the difference between a NodeList and an array and understanding how to iterate over a NodeList
- Grasping the concept of event bubbling and capturing
- Remembering to prevent default form submission behavior when handling form events with JavaScript
- Styling form controls consistently across different browsers
- Structuring and organizing complex forms with many input elements
- Understanding the difference between the
value
attribute and thechecked
property for radio buttons and checkboxes
- Merged previous lesson-12 pull request into main branch
- Created new lesson-13 branch from updated main branch
- Created a js folder at the same level as index.html, readme.md, and css folder
- Created an index.js file inside the js folder
- Linked the index.js file in the index.html file using a
<script>
element before the closing</body>
tag
- Added a
<footer>
element to the index.html using DOM manipulation - Placed the footer element correctly in the DOM tree
- Created a variable named
today
and assigned it a newDate
object - Created a variable named
thisYear
and assigned it the current year using thegetFullYear
method - Created a variable named
footer
and assigned it the footer element using DOM selection - Created a variable named
copyright
and used it to create a new<p>
element - Set the inner HTML of the
copyright
element to display the student's name and the current year - Appended the
copyright
element to thefooter
using DOM manipulation
- Added a new
<section>
element with an id attribute of "skills" above the "Connect" section in index.html - Added a
<h2>
element inside the new section with the text "Skills" - Added an empty unordered list (
<ul>
) element after the<h2>
element
- Created an array named
skills
containing a list of technical skills - Created a variable named
skillsSection
and used DOM selection to select the skills section by id - Created a variable named
skillsList
and used DOM selection to query theskillsSection
for the<ul>
element - Created a
for
loop to iterate over theskills
array - Inside the loop, created a variable named
skill
to create a new<li>
element - Set the inner text of the
skill
element to the current array element using bracket notation - Appended the
skill
element to theskillsList
element inside the loop
- Staged changes using
git add
- Committed changes with a meaningful commit message using
git commit
- Pushed changes to the GitHub repository using
git push
- Created a pull request for the lesson-13 branch
- Used Unicode to include the copyright symbol (©) in the footer content
The Intro Guidebook is created by Code the Dream staff and volunteers for Code the Dream volunteers. This is your tool – please feel free to suggest edits or improvements.
Overview of the wiki.
Onboarding guide for new volunteers.
Links to pages for specific assignments, including rubrics, overviews of student content, and mentor-created resources.