+ 3
first of all, you had a mistake here: let btn = document.qetElementById("qw"):hit() // its get not qet, and you dont need to add a colon and the function name If you want to use the event listener your code should look like: let btn = document.getElementById("qw") btn.addEventListener('click', hit) function hit() { console.log("Home"); } but you have to remove the onclick attribute from the html tag. if you want to use the onclick attribute you were missing parentheses. so it should be: <button id="qw" onclick="hit()" type="button" class="btn">Home</button> Then in your JS file all you need is: function hit() { console.log("Home"); }
12th Nov 2022, 8:50 AM
Mohamed Ghulam
Mohamed Ghulam - avatar
+ 4
https://code.sololearn.com/WgDgPXtwp0q4/?ref=app I removed your html "onclick" part, added the window.onload thing to the JS and fixed the event listener. g =/= q (be careful)
12th Nov 2022, 8:50 AM
Ausgrindtube
Ausgrindtube - avatar