Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
const input = document.getElementById("button");

function addingEventListener() {
alert("I was clicked!");
input.addEventListener("click", addingEventListener);
Comment on lines +4 to +5

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Be careful! In this case, you actually created a loop. When the event listener is triggered, it will add a new event listener each time, meaning it will stack each time the input is clicked. Compare what you have to something like this.

function addingEventListener() {
  const input = document.getElementById("button");

  function clickAlert() {
    alert("I was clicked!");
  }

  input.addEventListener("click", clickAlert);
}

}
Loading