Exercise 22
- Create the following folder/file structure:
/ex_22
|-- index.html
index.html
- Create a basic HTML document
- Create a script tag on the document head element
- Add the following html code
<!DOCTYPE html>
<html lang="en">
<head>
<title>Texts</title>
</head>
<body>
<h1>Main Title</h1>
<p>This is a paragraph</p>
</body>
</html>
- Select the h1 element
- Define a new variable and store the h1 element content using
innerText
- Select the p element
- Define a new variable and store the p element content using
textContent
- Replace the h1 element content for the paragraph one
- Replace the p element content for the title one
- Once this code gets executed we get the following result:
<h1>This is a paragraph</h1>
<p>Main Title</p>