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 trialKhumoyunmirzo Nosirov
8,689 PointsI couldn't find the error , can Anyone help me?
We have a page with 3 buttons. Our goal is to apply the spinElement callback to btn1, btn2, and btn3. The spinElement function should be triggered on the click event. Modify the code in the app.js file to add the event listener to every button.
const btn1 = document.getElementById("button1");
const btn2 = document.getElementById("button2");
const btn3 = document.getElementById("button3");
function spinElement(event) {
//Applies spinning animation to button element
event.target.className = "spin";
}
btn1.addEventElement('click', spinElement);
btn2.addEventElement('click', spinElement);
btn3.addEventElement('click', spinElement);
<!DOCTYPE html>
<html lang="en">
<head>
<title></title>
<link rel='stylesheet' href='styles.css'>
</head>
<body>
<section >
<button id='button1'>Button 1</button>
<button id='button2'>Button 2</button>
<button id='button3'>Button 3</button>
</section>
<script src='app.js'></script>
</body>
</html>
2 Answers
Byron Injeeli
Full Stack JavaScript Techdegree Graduate 25,639 PointsHi Khumoyunmirzo, you should be using the addEventListener
method to add callback functions to HTML elements:
btn1.addEventListener('click', spinElement);
Khumoyunmirzo Nosirov
8,689 Pointsthank you soooo much , you really helped me!
Byron Injeeli
Full Stack JavaScript Techdegree Graduate 25,639 PointsNo problem - could you please select my answer as the correct answer for this question? Thanks!
Khumoyunmirzo Nosirov
8,689 PointsKhumoyunmirzo Nosirov
8,689 PointsWhat did I do?
Byron Injeeli
Full Stack JavaScript Techdegree Graduate 25,639 PointsByron Injeeli
Full Stack JavaScript Techdegree Graduate 25,639 PointsKhumoyunmirzo, you were using
addEventElement
instead ofaddEventListener
.