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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T02:22:53+00:00 2026-05-31T02:22:53+00:00

The following code snipplet shows what my issue is: var $div = $(‘<div>’); $(‘span’).live(‘click’,

  • 0

The following code snipplet shows what my issue is:

var $div = $('<div>');

$('span').live('click', function() { this.innerHTML = 'changed'; });

$div.append(
    $('<span>span</span>').click()
);

$div.appendTo('body');
​

This works as expected in jQuery 1.6.x but not in 1.7.x

Why is it not working in 1.7.x? Is it a bug? Is there any way to get it to work in 1.7.x?

EDIT: .on doesn’t change anything!!

  • 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-31T02:22:54+00:00Added an answer on May 31, 2026 at 2:22 am

    The way that event handling works has changed in the 1.7 release. Before the <span> is added to the DOM, events triggered on it will not bubble up to the <body> as they once did (erroneously, in my opinion; the 1.7 behavior makes much more sense).

    The triggering of the event on the <span> probably works, but because the event does not bubble to the <body> the actual handler that deals with your .live() setup cannot be called.

    edit — it may be the document element to which events bubble; whatever, the point is the same.

    edit again — Here’s a way to make this work so that you can trigger handlers before adding your elements to the DOM:

    $('<div></div>').on('click', 'span', function() {
        this.innerHTML = "Changed!";
    }).append($('<span>span</span>'))
      .find('span').click().end()
      .appendTo($('body'));
    

    That sets up the “click” handler as a delegated handler on the nascent <div> directly. Then, after appending the new <span> to that element, it’s then possible to trigger a “click” on that <span> and have the handler be called. That happens before the whole thing is appended to the <body>.

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

Sidebar

Related Questions

This following code snippet works fine using jQuery1.2.3, but it doesn’t work with latest
I appear to be having an issue with the following snippet of code in
Possible Duplicate: Protected in Interfaces The following code snippet shows that an interface in
I have the following code snippet that shows a list of numbers, and highlights
I have the following SQL design issue. The code below might look a little
The following code snippet is a simplified version of my issue. Basically I'm trying
I have the following code: $('a.uiPopup').hover(function () { $('.uiTip').show(); }, function () { $('.uiTip').remove();
The following code snippet illustrates a memory leak when opening XPS files. If you
The following code snippet on SQL server 2005 fails on the ampersand '&': select
The following code snippet is from The Official GNOME 2 Developer's Guide : GMemChunk

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.