From the course: Learning App Building with Vanilla JavaScript
Unlock the full course today
Join today to access over 22,500 courses taught by industry experts or purchase this course individually.
Add and modify properties with vanilla JavaScript - JavaScript Tutorial
From the course: Learning App Building with Vanilla JavaScript
Add and modify properties with vanilla JavaScript
- [Instructor] JavaScript allows us to access a number of properties and methods of DOM elements, which we can use to customize the elements. These are part of the API that let's us manipulate elements programmatically using JavaScript. So scrolling down to line 79 in our app, we've created a few elements but they need some customization before we can use them. The container element is fine, but the p element, stored in the cityPara variable, needs a class value of city, which we can see up here in the JSX for our react component. So we can use the element's setAttribute method to specify both the attribute and its value. So we'll add a new line and we'll reference cityPara.setAttribute, and we'll give it two arguments. The first is a string class, and then a comma, and the second is the string city. So this says that we want to set the value of the class attribute to the string city. Now we also want this p element to have content which is going to be text. Now there are a few ways…
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.