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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T00:04:52+00:00 2026-05-24T00:04:52+00:00

Following is a piece of jquery code that is driving me nuts var count

  • 0

Following is a piece of jquery code that is driving me nuts

var count = 0;
    $('#some-element-id').click(function(){
        var currentElement = '#new-div-id-'+count;
        $(currentElement).after($('<div id="new-div-id-'+(++count)+'">Hello World!<span class="delete_me">x</span></div>'));
});

$(".delete_me").click(function () {
  alert('Deleting!');
});

Now accordingly when I click on element with id some-element-id a new div is inserted and I see the x character. But clicking x doesn’t do any thing. No error. As per http://api.jquery.com/after I can insert elements this way which is working fine. I can ee the new elements in DOM tree using Firebug. Now why no event is fired when I click on span? For some unknown reason I am forced to use jQuery 1.3.2 but that should not be a problem.

Update 1
I understand that I am trying to bind an even to an element that doesn’t exist in the DOM. But please note that even is not fired, the event will be fired after the element is embedded in the DOM. I used following code and even it doesn’t work

$("span.delete_me").live('click',function () {
  alert('Deleting!');
});

There is no error on the console.
Update 2
Here is the actual rendered code http://jsfiddle.net/8sjcZ/

  • 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-24T00:04:53+00:00Added an answer on May 24, 2026 at 12:04 am

    See http://jsfiddle.net/vKwm6/

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

Sidebar

Related Questions

I am using the following piece of jQuery code: $('div#addMenu1').click(function(){ if (!menuSet1){ menuSet1 =
I've got the following piece of Jquery: $(#collapse-menu > li > a).click(function() { $(this).toggleClass(expanded).toggleClass(collapsed).find(+
I have the following piece of code: jQuery.fn.shake = function(intShakes, intDistance, intDuration) { this.each(function()
I have the following piece of code: function checkAmount() { var PayField = document.getElementById('paymentamount');
Say you have the following piece of code: function someProcess() { var deferred =
I'm using jQuery with rails and have the following piece of code $('#related').html(<%= render
Imagine the following markup: <a href=#link01>1</a> <a href=#link02>2</a> And: $('a').click(function(){ var href = $(location).attr('href'),
I am trying to convert the following code to work with jquery: var req
In a piece of example code I wrote var as = toArray(document.getElementsByClassName(false)).filter(function (el) {
I have a piece of jQuery code that, when the user changes the value

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.