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 8766349
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T16:31:48+00:00 2026-06-13T16:31:48+00:00

I start with an empty page. If I run document.body.onclick I get null .

  • 0

I start with an empty page. If I run document.body.onclick I get null. If I apply following code:

document.body.onclick = function() { return "Click"; };

I get function() { return "Click"; } when I run document.body.onclick. That makes sense! But when I run

document.body.addEventListener("click", function() { return "Click"; });

document.body.onclick is still null, but the output is "Click" when I run document.body.click().

So my question is, where is the function stored when using addEventListener?

  • 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-13T16:31:49+00:00Added an answer on June 13, 2026 at 4:31 pm

    Its stored in the actual list (array) of Event listeners for body.

    Elements have a list of function references in them for their event listeners. These references are not in the DOM. When firing an event, the browser has to run thru all the appropriate elements looking for these references and running them in order.

    Anyhow… There is plenty going on in the background that the DOM does not see. The entire event system is one of them. And well, the whole Javascript engine essentially and with a large object tree for the current loaded page, all stored in mysterious memory. They are generally accessed by using the document and window interfaces, just like the DOM. But properly registered events will be in this large object tree that’s stored in memory, which is not the same as the DOM. Just closely related. I view the DOM as an interface or middle-man between this large object tree and the HTML itself.

    Moving on… onclick is limited to just one value or a single string of javascript just sitting there in the DOM. Not actually registered. So, not an actual Event listener. Here the DOM is kind of like a shim in that it props up the onclick strings to run as events. So that this string also gets run when the event is fired. By the browser, at the right time, mysteriously. In a round about way, it could be said that is part of what the DOM does in general, it shims in all the in-line text like this from HTML, so that its accessible by document. But generally, they are just stored as strings instead of actual objects in the tree. This is probably one of many reasons why the DOM is so foobar.

    Whereas addEventListenener actually registers it as a real event, thus you can:

    • Have multiples
    • Access them as objects
    • Add and remove them at will
    • Select an event propagation scheme
    • Control event propagation itself during runtime
    • Have the event auto remove itself after first run

      … and a few other features.

    They are both, sort-of, two different event listeners for the same event. One is a full event listener when using addEventListener. And the other is just a string of text sitting in the DOM that the browser will run “at the right time”, but not a actual full event listener.

    This question might shed some light… addEventListener vs onclick

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

Sidebar

Related Questions

If I start from an empty class (TestClass) in Netbeans and add the following
I have written following function which checks whether start_date field is not empty and
I get the following error in Chrome every time I try to run my
I would like to build something like this: at start an empty page with
Let's start with code: <html> <head> <title>Opera bug test</title> <script type=text/javascript> function callTest() {
I have UL in my page, and it is empty. I start populating it
I start out with an empty list and prompt the user for a phrase.
I start a download using PHP with this code: <? $_REQUEST['file'] = urldecode($_GET['file']); header(Content-type:
At the top of my page I have this piece of code to check
I am having trouble getting this code to run using Google Chrome(I have not

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.