Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialRipalben Patel
6,193 Pointssetting a Reset button.
I am trying to set reset button but when I preview it it doesn't work. here is the code for app.js file: const myHeading = document.getElementById('myHeading'); const myButton = document.getElementById("myButton"); const reset = document.getElementById("reset");
myButton.addEventListener('click', () => {
myHeading.style.color = 'purple';
});
reset.addEventListner("click", () => {
myHeading.style.color = "black";
})
below is the code for HTML: <!DOCTYPE html> <html> <head> <title>JavaScript and the DOM</title> <link rel="stylesheet" href="css/style.css"> </head> <body> <h1 id="myHeading">JavaScript and the DOM</h1> <p>Making a web page interactive</p> <button id= "myButton">Change the color of Heading</button> <button id= "reset">Reset</button> <script src="app.js"></script> </body> </html>
2 Answers
Steven Parker
231,271 PointsI managed to spot a typo even in the unformatted code:
You wrote "addEventListner" (missing an "e") instead of "addEventListener".
Fix that and it will work.
Stivan Radev
1,475 Pointsconst myHeading = document.getElementById('myHeading');
const myButton = document.getElementById("myButton");
const reset = document.getElementById("reset");
myButton.addEventListener('click', () => {
myHeading.style.color = 'purple';
});
reset.addEventListner("click", () => {
myHeading.style.color = "black";
})
<!DOCTYPE html>
<html>
<head>
<title>JavaScript and the DOM</title>
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<h1 id="myHeading">JavaScript and the DOM</h1>
<p>Making a web page interactive</p> <button id="myButton">Change the color of Heading</button> <button id="reset">Reset</button>
<script src="app.js"></script>
</body>
</html>
CORRECT FORMAT NOT ANSWERED
Ripalben Patel
6,193 PointsThank you Steven. It worked. :)
Steven Parker
231,271 PointsSteven Parker
231,271 PointsWhen posting code, use the instructions for code formatting in the Markdown Cheatsheet pop-up below the "Add an Answer" area. Or watch this video on code formatting.