Challenge: Add and Remove DOM Elements
Task
You're building a shopping cart where users can add and remove items.
- Add an Item to the Cart:
- Create a new
<li>element; - Create a new
<button>element; - Add new
<button>element to the new<li>element; - Add a new
<li>element to the<ul>with thecart-listID.
- Create a new
- Remove an Item from the Cart: Delete the specific
<li>element from the<ul>.
index.html
index.css
index.js
- Use
createElementto create a new<li>element; - Use
createElementto create a new<button>element; - Use
appendChildto add new<button>element to the<li>element; - Use
appendChildto add a new<li>element to the<ul>with the IDcart-list; - Use
removeChildto delete the specific<li>element from the<ul>.
index.html
index.css
index.js
Everything was clear?
Thanks for your feedback!
SectionΒ 2. ChapterΒ 11
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat
Suggested prompts:
Can you show me an example of how to add an item to the cart using JavaScript?
How do I remove a specific item from the cart?
Can you explain how the remove button should work for each cart item?
Awesome!
Completion rate improved to 2.22
Challenge: Add and Remove DOM Elements
Swipe to show menu
Task
You're building a shopping cart where users can add and remove items.
- Add an Item to the Cart:
- Create a new
<li>element; - Create a new
<button>element; - Add new
<button>element to the new<li>element; - Add a new
<li>element to the<ul>with thecart-listID.
- Create a new
- Remove an Item from the Cart: Delete the specific
<li>element from the<ul>.
index.html
index.css
index.js
- Use
createElementto create a new<li>element; - Use
createElementto create a new<button>element; - Use
appendChildto add new<button>element to the<li>element; - Use
appendChildto add a new<li>element to the<ul>with the IDcart-list; - Use
removeChildto delete the specific<li>element from the<ul>.
index.html
index.css
index.js
Everything was clear?
Thanks for your feedback!
SectionΒ 2. ChapterΒ 11