From the course: Building Website Interactivity with JavaScript
Unlock this course with a free trial
Join today to access over 25,500 courses taught by industry experts.
Using data attributes for dynamic labeling - JavaScript Tutorial
From the course: Building Website Interactivity with JavaScript
Using data attributes for dynamic labeling
- [Instructor] The functionality we've set up works well, but we're currently hard coding the button label here in the JavaScript. This is not ideal. And in this video, we'll use data attributes to improve the approach. Generally speaking, it's a good idea to avoid hard coding content in our JavaScript. Content is generally the realm of our HTML, so keeping as much of our content in here as possible makes maintenance easier. With that in mind, it would be better to include the changing button labels in the HTML with the rest of the information. To do that, let's add some data attributes. These can be anything you like. They start with the word data, and a hyphen, and then you can include as many words as you want, as long as they're all lowercase and have hyphens separating the words. So in this case, we'll use label-show, and data-label-hide. And again, these could be as many words as you like. So when we're showing, we want this to say, "Show Password", and when we're hiding, we…
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
-
-
-
-
Understanding an accessible sign in form2m 48s
-
(Locked)
Toggling the password via type change7m 16s
-
(Locked)
Using data attributes for dynamic labeling2m 57s
-
(Locked)
Syncing and swapping with a text field9m 6s
-
(Locked)
Challenge: Sign up form with confirmation of password1m 38s
-
(Locked)
Solution: Sign up form with confirmation of password4m 11s
-
-
-
-
-
-