- Introduce native JavaScript for manipulating the Document Object Model
- createElement
- appendChild
- getElementById
- getElementsByTagName
- getElementsByClassName
- querySelector
- querySelectorAll
- manipulating attributes
- manipulating classes
Assumes: You already understand basic JavaScript.
Given a simple page, for example the following,
<html>
<body>
</body>
</html
...create and append an h1
element, like <h1>hello world</h1>
, to the body of the page.
Hint: A web-based development tool like codepen or jsfiddle can be very useful to play with these concepts.
Given the following html page,
<html>
<body>
<div>MY LOGO</div>
<div id="site-title">My Website</div>
<div id="site-tagline">The best site ever.</div>
</body>
</html>
...modify the style of the site title (the element with the text "My Website" and the ID site-title
) to render it in the color blue. Only one line should become blue!
Given the following html page,
<html>
<head>
<style type="text/css">
.highlighted { background-color: yellow; }
</style>
</head>
<body>
<div class="heading-text primary">My Website</div>
<div class="heading-text secondary">The best site ever.</div>
<div class="body-text primary">I love web development.
<div class="child-text">It's fun</div>
</div>
<div class="body-text secondary">It's magical.</div>
</body>
</html>
...find the page element that has both the class heading-text
and the class secondary
and add the class highlighted
. This will cause that line to become highlighted in yellow. Only one line should be highlighted!
...now find the page element that has both the class body-text
and the class primary
with a child element that has class child-text
. Add the class highlighted
. This will cause that line to become highlighted. You should now have two lines highlighted.