new to js ... i tried my best to display alert box in browser, this are my html and js file
<!DOCTYPE html>
Document
click here
</html
var any = document.getElementsByClassName("try");
any.addEventListener('click' , () =>{
alert('you clicked!');
});
Top comments (2)
Hello,
getElementsByClassName - note the plural, this will return a node list, not a single element to add an event listener to.
You probably want getElementById and set the id on the html element instead of the class
Some comments may only be visible to logged-in visitors. Sign in to view all comments.