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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:12:41+00:00 2026-05-26T19:12:41+00:00

How do I attach events to elements created in the future in jQuery, only

  • 0

How do I attach events to elements created in the future in jQuery, only once?

I understand that .live() works in attaching events for elements created in the future, but will attach events multiple times like .bind() does. But I need to attach the event only once.

EXAMPLE:

For my case

http://jsfiddle.net/ppTqp/1/ -> Should alert “Live from test” only once. With .live method it alerts twice.

  • 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-26T19:12:42+00:00Added an answer on May 26, 2026 at 7:12 pm

    Update:

    Apparently you want that an event handler is only bound once when you make several calls to live, delegate or on.

    In this case you’d have to unbind the event handler first. You can use namespaces to only unbind the specific event handler:

    $(document).off('click.namespace').on('click.namespace', selector, function() {
    
    });
    

    In case of live, you have to call die:

    $(...).die('click').live(...)
    

    I assume the event handler is bound to several elements. Due to the nature of live, delegate or on (for that matter), you cannot just “unbind” the event handler when it was executed for one element, as it won’t be fired for any other element anymore. Instead, uou have to keep track for which element it was fired.

    Example:

    $(document).on('click', selector, function() {
        if(!$(this).data('fired')) {
            $(this).data('fired', true);
            // do your stuff
        }
    });
    

    The other solution would be to use .one() and bind the event handler whenever you create new elements.


    Regarding your terminology:

    You cannot attach events, but event handlers. bind does not attach events or event handlers multiple times, just once, but once it is bound, it will always fire for a certain event. If you want to an event handler to be called only once, you have to unbind it after it was called.

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

Sidebar

Related Questions

jQuery has functions like .on() and .trigger() that let you attach events to DOM
When I use jQuery to attach events to elements, I typically do it like
Does jquery/javascript have any event model that you can attach to your objects? Basically
I need to attach a single event handler to multiple DOM elements using jQuery.
I am trying to attach 'click' events to all elements of a particular class.
I usually just use # to attach events to click-able elements without a url,
I want to attach a event to dynamically created element class.So i used live
jQuery's 'live' method is unable to handle multiple events. Does anyone know of a
I would like to create a jQuery function that I can attach to form
I can see how to attach an event to an object that has no

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.