Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Challenge: Modifying Element Styles | DOM Manipulation
Advanced JavaScript Mastery
course content

Course Content

Advanced JavaScript Mastery

Advanced JavaScript Mastery

1. Classes
2. DOM Manipulation
3. Events and Event Handling
4. Asynchronous JavaScript and APIs

bookChallenge: Modifying Element Styles

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.

  1. Change Inline Styles: When the button is clicked:
    • Change the background color of the <div> with ID card to "lightblue";
    • Set the width of the card to "300px";
    • Add a 2px solid #333 border around the card.
  2. Toggle a Highlight Class: When the button is clicked:
    • Add or remove the highlight class on the <div> with ID card.
  3. Add a Dark Theme Class: When the button is clicked:
    • Add or remove the dark-theme class on the <body>, which should switch the page's theme.
html

index

css

index

js

index

copy
  • Use style.backgroundColor to change the background color of the <div> with ID card to "lightblue";
  • Use style.width to set the width of the card to "300px";
  • Use style.border to add a 2px solid #333 border around the card;
  • Use classList.toggle() to add or remove the highlight class on the <div> with ID card;
  • Use classList.toggle() to add or remove the dark-theme class on the <body>, which should switch the page's theme.
html

index

css

index

js

index

copy

Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 2. Chapter 13
some-alt