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

  • Home
  • SEARCH
  • 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 5939147
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T15:47:07+00:00 2026-05-22T15:47:07+00:00

I understand the difference between an addEventListener and the onclick property and know how

  • 0

I understand the difference between an addEventListener and the onclick property and know how to use both. I am wondering if there is a draw back to always using EventListener‘s instead of using the onclick property. The EventListener appears to be much more powerful than just using the onclick atleast when dynamically generating the HTML from javascript.

Is there a memory/cpu drawback or am I safe to only use EventListeners?

  • 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-05-22T15:47:08+00:00Added an answer on May 22, 2026 at 3:47 pm

    This probably isn’t the direction you were going in, but there are a few instances where you would be unable to remove an event listener.

    Event handlers are completely public, and can be modified (to a certain extent) by anyone:

    // You do this
    myLink.onclick = function () {
        alert('hello, world');
    };
    
    // Another developer who hates you because
    // he thinks that you're hitting on his girlfriend
    // but you're not, you're just friends, but
    // he's jealous so he doesn't understand
    // does this
    myLink.onclick = function () {
        alert('muahahahaha');
    };
    
    // Someone else could even get rid of
    // the handler entirely:
    myLink.onclick = null;
    

    But there is no publically accessible list of event listeners. The only way to remove an event listener is if you still have access to the original function:

    myLink.addEventListener('click', function () {
        alert('hello, world');
    }, false);
    

    There is now no way to remove that event listener. You gave it an anonymous function, so even you wouldn’t be able to remove it if you wanted to.

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

Sidebar

Related Questions

Yes, I do understand the difference between them. What I want to know is:
Is there any substantial difference between those two terms?. I understand that JDK stands
I am trying to understand difference between those two and really need a explanatory
I understand the difference between String and StringBuilder ( StringBuilder being mutable) but is
I do not quite understand the difference between a C# reference and a pointer.
I understand how the implementation of dynamic binding works and also the difference between
What is the difference between private and protected members in C++ classes? I understand
I've been researching the difference between these two patterns. I understand that facade encapsulates
I understand the difference between a Mock and a Stub. But different types of
I am trying to understand the difference between mysqli's query() and prepare(). I have

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.