From the course: JavaScript Essential Training
Unlock the full course today
Join today to access over 24,000 courses taught by industry experts.
Modifying element classes - JavaScript Tutorial
From the course: JavaScript Essential Training
Modifying element classes
- [Instructor] A common task in JavaScript is to modify the classes of an element in some way. This is a simple way of changing the appearance or behavior of an element without having to inject CSS into the HTML itself. Instead, we just add a class or remove a class to make something happen. Examples of this include hiding and showing a panel, or highlighting a button when something else has happened, like now that you've done step one, click here to continue, et cetera. Class manipulation is common enough, that we have two specialized properties for it. The first one and the oldest one is class name, and it's available for all elements in the dom. Class name holds a string, listing out all the classes appended to an element. We can see it if we go to our exercise files and the console. So the H1 here has the class backpack name, and we can call up the H1 in JavaScript and get just that output. So document, query…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
-
DOM: The Document Object Model4m 7s
-
(Locked)
Access elements with querySelector methods6m 6s
-
(Locked)
Access elements using older methods3m 45s
-
(Locked)
Practice: Find an element1m 29s
-
(Locked)
Modifying element classes4m 53s
-
(Locked)
Attributes4m 13s
-
(Locked)
Inline style3m 52s
-
(Locked)
Practice: Modify classes and attributes, and styles1m 36s
-
(Locked)
Add DOM elements5m 25s
-
(Locked)
Challenge intro: Create elements1m 17s
-
(Locked)
Solution: Create elements3m 35s
-
-
-
-
-
-
-