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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T21:45:21+00:00 2026-05-21T21:45:21+00:00

I have an event handler registration code like this $(sel).each(function() { (function(a){ var b

  • 0

I have an event handler registration code like this

$("sel").each(function() {
        (function(a){
            var b = createb();          
            //do some more ops
            a.addEventListener('evttype',handler1(a, b),false);
            b.addEventListener('evttype',handler2(a, b),false);         
        })(this);
});

This binds the even ‘eventtype’ with all the element (a) selected by (“sel”) , and also creates another element(b) and bind to it as well. It only works for static elements, of course. Now I want to register for all ‘a’ which are dynamically created. I read about two API for this live() and delegate(). I could not think a way to make this work.

$('sel').delegate("a", "evttype", function(){
var b = createb();          
//do some more ops
b.addEventListener('evttype',handler2(a, b),false); 
});

the code is wrong as it creates a ‘b’ every time the event is handled. This is not the same as the first block of code. I only need to create the element ‘b’ once, and bind the same event to both of it, and they handle them separately. Is there an interface to match all the future elements based on the selector, or is there an easy way with delegate().

thanks for ur time.
bsr.

  • 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-21T21:45:22+00:00Added an answer on May 21, 2026 at 9:45 pm

    there is http://api.jquery.com/live exactly for that purpose

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

Sidebar

Related Questions

I have an event handler set up using plain javascript like this: myElement.addEventListener('drop', handleDrop,
I have an event handler in C# code-behind for an .aspx page. Each time
I have an event handler that needs to determine a type and execute code
I have an Event Handler that overrides the ItemAdded method. This works fine on
I have an event handler in code that I see is getting called multiple
I have an event handler subscribed to the FormClosing event. This event handler provides
I have a div and I'd like to have an event handler listen to
I have an event handler listening on a jQuery-"submit" event. The form looks like
I have an event handler attached to a class, as so: $('#container').on('click', '.myClass', function
I have an asp button (the code is below). I have the event handler

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.