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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T00:55:11+00:00 2026-06-17T00:55:11+00:00

Is possible to add event listener (Javascript) to all dynamically generated elements? I’m not

  • 0

Is possible to add event listener (Javascript) to all dynamically generated elements?
I’m not the owner of the page, so I cannot add a listener in a static way.

For all the elements created when the page loaded I use:

doc.body.addEventListener('click', function(e){
//my code
},true);

I need a method to call this code when new elements appear on the page, but I cannot use jQuery (delegate, on, etc cannot work in my project). How can I do this?

  • 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-17T00:55:13+00:00Added an answer on June 17, 2026 at 12:55 am

    It sounds like you need to pursue a delegation strategy without falling back to a library. I’ve posted some sample code in a Fiddle here: http://jsfiddle.net/founddrama/ggMUn/

    The gist of it is to use the target on the event object to look for the elements you’re interested in, and respond accordingly. Something like:

    document.querySelector('body').addEventListener('click', function(event) {
      if (event.target.tagName.toLowerCase() === 'li') {
        // do your action on your 'li' or whatever it is you're listening for
      }
    });
    

    CAVEATS! The example Fiddle only includes code for the standards-compliant browsers (i.e., IE9+, and pretty much every version of everyone else) If you need to support “old IE’s” attachEvent, then you’ll want to also provide your own custom wrapper around the proper native functions. (There are lots of good discussions out there about this; I like the solution Nicholas Zakas provides in his book Professional JavaScript for Web Developers.)

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

Sidebar

Related Questions

I wonder if it's possible to add an Event Listener to a MovieClip that
Possible Duplicate: Javascript closure inside loops - simple practical example I add event handlers
Possible Duplicate: Javascript event handler on body but not on input I wrote a
Possible Duplicate: JavaScript: remove event listener I am adding some listener in my html
Possible Duplicate: Javascript prototype ‘this’ issue I have an event listener which of course
Is it possible to have keyboard event listener canvas.addEventListener('onkeydown', ev_keydown, false); like we have
Is it possible to add button click event by clicking design of axml? if
Possible Duplicate: VB.NET RemoveHandler & Anonymous Methods If I add an event handler like
I am trying to add an event listener to respond to hovering over a
Is that possible to fire Flash-button click-event via javascript ? it`s my code ,

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.