Challenge: Apply Dynamic Styles to DOM Elements
Task
You're building an interactive card that can change its appearance based on user actions. Users can change the background color of the card, resize it, and toggle a "highlighted" state for additional styling.
- Change Inline Styles: When the button is clicked:
- Change the background color of the
<div>with IDcardto"lightblue"; - Set the width of the card to
"300px"; - Add a
2px solid #333border around the card.
- Change the background color of the
- Toggle a Highlight Class: When the button is clicked:
- Add or remove the
highlightclass on the<div>with IDcard.
- Add or remove the
- Add a Dark Theme Class: When the button is clicked:
- Add or remove the
dark-themeclass on the<body>, which should switch the page's theme.
- Add or remove the
index.html
index.css
index.js
- Use
style.backgroundColorto change the background color of the<div>with IDcardto"lightblue"; - Use
style.widthto set the width of the card to"300px"; - Use
style.borderto add a2px solid #333border around the card; - Use
classList.toggle()to add or remove thehighlightclass on the<div>with IDcard; - Use
classList.toggle()to add or remove thedark-themeclass on the<body>, which should switch the page's theme.
index.html
index.css
index.js
Thanks for your feedback!
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat
Can you show me how to implement the button that changes the card's appearance?
How should the CSS for the `highlight` and `dark-theme` classes look?
Can you provide a complete example with HTML, CSS, and JavaScript?
Awesome!
Completion rate improved to 2.22
Challenge: Apply Dynamic Styles to DOM Elements
Swipe to show menu
Task
You're building an interactive card that can change its appearance based on user actions. Users can change the background color of the card, resize it, and toggle a "highlighted" state for additional styling.
- Change Inline Styles: When the button is clicked:
- Change the background color of the
<div>with IDcardto"lightblue"; - Set the width of the card to
"300px"; - Add a
2px solid #333border around the card.
- Change the background color of the
- Toggle a Highlight Class: When the button is clicked:
- Add or remove the
highlightclass on the<div>with IDcard.
- Add or remove the
- Add a Dark Theme Class: When the button is clicked:
- Add or remove the
dark-themeclass on the<body>, which should switch the page's theme.
- Add or remove the
index.html
index.css
index.js
- Use
style.backgroundColorto change the background color of the<div>with IDcardto"lightblue"; - Use
style.widthto set the width of the card to"300px"; - Use
style.borderto add a2px solid #333border around the card; - Use
classList.toggle()to add or remove thehighlightclass on the<div>with IDcard; - Use
classList.toggle()to add or remove thedark-themeclass on the<body>, which should switch the page's theme.
index.html
index.css
index.js
Thanks for your feedback!