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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T16:35:21+00:00 2026-06-04T16:35:21+00:00

Using .live() : <input type=button value=button /> $(:input[type=button]).live({ click: function() { $(this).after(‘<input type=button value=new

  • 0

Using .live() :

<input type="button" value="button" />

$(":input[type=button]").live({
      click: function() {
            $(this).after('<input type="button" value="new" />');
      },
      mouseover: function() {
            //do something
      },
      mouseout: function() {
            //do something
      }
    });

DEMO : http://jsfiddle.net/F9gC4

Here delegation works fine. If we click ‘button’ or ‘new’, new button element will be created.

Using .on() :

<input type="button" value="button" />

$(":input[type=button]").live({
      click: function() {
            $(this).after('<input type="button" value="new" />');
      },
      mouseover: function() {
            //do something
      },
      mouseout: function() {
            //do something
      }
    });

DEMO : http://jsfiddle.net/CB8fh

Here delegation doesn’t work. ‘new’ button click doesn’t create element(can’t fire)

So how can we use .on() multiple event handlers with delegation(future element)?

Is this possible?

  • 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-04T16:35:22+00:00Added an answer on June 4, 2026 at 4:35 pm

    Try this code:

    $(document).on({
          click: function() {
                $(this).after('<input type="button" value="new" />');
          },
          mouseover: function() {
                //do something
          },
          mouseout: function() {
                //do something
          }
    }, ':input[type=button]');​
    

    For delegation to work with created/future elements you need to attach the event to document and use the ‘selector’ argument of the .on function to target the event. Not tested, but in theory should work! See documentation for the on function and also the documentation for live has a section on moving to the .on function.

    Edit just wanted to add, as @Joy said in his answer, you don’t need to attach to document, the closer to the target element you delegate to the better (although you need to be sure that element will not be affected by ajax/dom changes that might remove the event handler).

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

Sidebar

Related Questions

After dynamically creating an element with this: $('#btnAddBanner').click(function () { var uid = new
I have this very simple button that I would like to hide <input type=button
I'm using this jQuery function to jumping on input styled components of the form:
Hy, I have a live username validation using ajax : <td id=user_process_live><input type=text id=user_live_ver
I'm using the following jQuery script to highlight a table row on mouseover. input.find(tr).live('mouseover
I am using Lemonstand (an e-commerce CMS) and after going live with our site
using (var file_stream = File.Create(users.xml)) { var serializer = new XmlSerializer(typeof(PasswordManager)); serializer.Serialize(file_stream, this); file_stream.Close();
CSS : form input:not([type='button']),form input:not([type='submit']) { width: 200px } HTML : <form> <input type='button'
Here is my jQuery using delegate and ajax: $(.tweets).delegate(#fav #submit, click, function(){ var favid
currently I have following code: home.php <form name='myformname' id='myformid'> <input type='text' name='mytext1' value='abc'> <input

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.