Welcome to your storybook coding adventure! You'll learn how to add dropdown menus using JavaScript's appendChild
and removeChild
methods.
Add a dropdown menu to every page of the storybook using JavaScript!
document.querySelector()
- Find elements on the pagedocument.createElement()
- Create new HTML elementsappendChild()
- Add elements to the pageremoveChild()
- Remove elements from the pageonclick
events - Make buttons interactiveindex.html
<div class="dropdown-container">
<button class="dropdown-button" onclick="toggleDropdown()">⚙️ Story Tools</button>
</div>
toggleDropdown()
function by filling in the ???
parts:
const container = document.querySelector('.dropdown-container');
const existingMenu = container.querySelector('.dropdown-menu');
container.removeChild(existingMenu);
const menu = document.createElement('div');
and menu.className = 'dropdown-menu';
document.createElement('button')
container.appendChild(menu);
Once index.html
works:
toggleDropdown()
function to all other pageswindow.history.back()
For each page, create these menu items:
style.css
window.location.href = 'page.html'
to navigate to pageswindow.history.back()
to go back to the previous pagealert('message')
to show popup messagesnew Audio('sound.mp3').play()
for clicksindex.html
in your browserstorybook-student/
├── index.html ← Start here!
├── page2a.html ← Forest path
├── page2b.html ← Mountain path
├── page3a.html ← Ending A
├── page3b.html ← Ending B
├── style.css ← Styling (already done!)
├── README.md ← Markdown version
└── README.html ← You're reading this!
Show your teacher your working storybook! Be ready to explain:
appendChild()
adds elements to the pageremoveChild()
removes elements from the pageGood luck, and have fun coding your interactive storybook! 🚀