Lesson 3
~22 min

DOM Manipulation Mastery

Master adding, removing, and modifying HTML elements dynamically

BEGINNER
Progress0%
1

Adding and Removing Classes

CSS classes are one of the most powerful ways to change how elements look! YakaJS makes it super easy to add, remove, or toggle classes dynamically. **The methods:** - .addClass('myClass') - adds a class - .removeClass('myClass') - removes a class - .toggleClass('myClass') - adds if not present, removes if present - .hasClass('myClass') - checks if class exists Think of classes as tags you can stick on elements to give them styles!
Key Points
  • addClass/removeClass change element styling
  • toggleClass is great for switching states (open/closed, active/inactive)
  • Always use classes for styling, not inline styles when possible

Try It Yourself

Practice Exercise

Modify the code below and run it to see the results.

Step 1 of 6