Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7860975
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T22:30:43+00:00 2026-06-02T22:30:43+00:00

elemen.addEventListener(‘click’,func,false); elemen.addEventListener(‘click’,func,false); When elemen is clicked, will the function func be called twice, or

  • 0
elemen.addEventListener('click',func,false);
elemen.addEventListener('click',func,false);

When elemen is clicked, will the function func be called twice, or just once?

If it is called twice, then is there a solution to check if the same event listener already exists on elemen?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T22:30:46+00:00Added an answer on June 2, 2026 at 10:30 pm

    In your example, func will not be called twice on click, no; but keep reading for details and a "gotcha."

    From addEventListener in the spec:

    If multiple identical EventListeners are registered on the same EventTarget with the same parameters the duplicate instances are discarded. They do not cause the EventListener to be called twice and since they are discarded they do not need to be removed with the removeEventListener method.

    (My emphasis)

    Here’s an example:

    const target = document.getElementById("target");
    
    target.addEventListener("click", foo, false);
    target.addEventListener("click", foo, false);
    
    function foo() {
        const  p = document.createElement("p");
        p.textContent = "This only appears once per click, but we registered the handler twice.";
        document.body.appendChild(p);
    }
    <input type="button" id="target" value="Click Me">

    It’s important to note, though, that it has to be the same function, not just a function that does the same thing. That’s because it works by looking for the function on the element’s handler list, and two distinct functions — even if equivalent — aren’t the same:

    const f1 = () => {};
    const f2 = () => {};
    console.log(f1 === f2); // false

    For example, here I’m hooking up four separate functions to the element, all of which will get called:

    const target = document.getElementById("target");
    
    for (let count = 0; count < 4; ++count) {
        target.addEventListener("click", () => {
            const p = document.createElement("p");
            p.textContent = "This gets repeated.";
            document.body.appendChild(p);
        }, false);
    }
    <input type="button" id="target" value="Click Me">

    That’s because on every loop iteration, a different function is created (even though the code is the same).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Example code: element.addEventListener('click',function () { this.style.backgroundColor = '#cc0000' //after element was clicked once what
Something like: element.addEventListener("displayChanged", function(){ console.log("element.style.display changed.") }, false); Of course, there is no displayChanged
function onBodyLoad() { document.addEventListener(deviceready,onDeviceReady,false); //for testing in safari only, comment out for deploy to
When registering an event via addEventListener on an element, then delete that element without
I'm trying to find the jQuery equivalent of this JavaScript method call: document.addEventListener('click', select_element,
Is there anyway to remove an event listener added like this: element.addEventListener(event, function(){/* do
I'm about to update my code to use addEventListener() over just writing to the
Possible Duplicate: JavaScript Event Listeners vs Event Handlers element.onload vs element.addEventListener(“load”,callbak,false) I've read this
On this page: https://developer.mozilla.org/en/DOM/element.addEventListener It is warned that the value of this will be
I'm try to implement caption display in html5, something like: video_element.addEventListener('CUE=11ms',show_sub1,false) how can I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.