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 trialtoddschneider
4,795 PointsDo Chrome and Firefox still support the (DOM) onclick and addEventListener?
I have been trying for over a hour to get my <button> element to work in JavaScript, using both addEventListener and onclick. I was wondering if the browsers no longer support these DOM commands? Here is my code just in case.
<button id="action">Action</button> <input id="text_field"> <script src="./functions.js"></script>
javascript var button = document.getElementById('action');
button.addEventListener('click', function () { console.log("hello"); });
Thanks to all who answer!
1 Answer
Andrew Kiernan
26,892 PointsHey Todd!
Firefox and Chrome both fully support addEventListener() and onclick(). If you want to share some more of your code, I'd be glad to take a look and see if I can help. Let me know!
-Andrew
toddschneider
4,795 Pointstoddschneider
4,795 PointsThanks for your comment Andrew. I was able to get my code to finally run here's the final productCode The problem was I tried to getElementById() above my slot Function so the browser wasn't able to define them when I call them below. Thanks again I hope I didn't put you on a wild goose chase! =D