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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T14:26:06+00:00 2026-06-10T14:26:06+00:00

I am working on dynamically adding a link with a click event handler after

  • 0

I am working on dynamically adding a link with a click event handler after a series of span tags on a page. The link is being added to the page, but when clicked the event handler is not firing. There are no errors recorded in the web console. I am sure that I am missing something obvious in the below code:

function changeClicked (e) {
    e.preventDefault();
    console.log('should work');
}

function initChangeOwner() {
    var changeLink = $('<a />', {
        href: '#',
        text: 'change',
        'class': 'changeLink',
        click: changeClicked
    });

    var licenseFor = $('[id*="LicenseFor"]').after(changeLink);
}

$(document).ready(function () {
    initChangeOwner();
    // other inits
});

Why is my click event handler not firing? For those who like to fiddle I have setup an example on jsFiddle.

* This is an older application which utilizes jQuery 1.4.1. Unfortunately, now is not the time to update the reference to a new version.

  • 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-10T14:26:07+00:00Added an answer on June 10, 2026 at 2:26 pm

    There is no need to get fancy on dynamic bindings in your particular case.
    Seeing you are in control when adding the elements and you want to bind the event at that time you can just bind you click event separately after you attached the elements.

    function initChangeOwner() {
        var changeLink = $('<a />', {
            href: '#',
            text: 'change',
            'class': 'changeLink'
        });
    
        var licenseFor = $('[id*="LicenseFor"]').after(changeLink);
    
        // Now the elements exist and you can bind the click event using the 'changeLink' class as a selector.
        $(".changeLink").click(function(event){changeClicked(event);});
    
    }
    

    DEMO – Bind after elements are created

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

Sidebar

Related Questions

I've got a page where I'm dynamically adding elements to a from a series
I am dynamically adding an image to a canvas object which was working for
I'm working on a web page where I have a dynamically generated table where
I'm adding a dynamically built set of checkboxes to an asp.net page from the
I am working on creating some grails domain objects dynamically and then adding them
I'm dynamically adding content (using AJAX) to my pages. This is working fine, except
I am working on java swing application and I am adding components dynamically in
I am working on a app where i need to get the click event
I'm working on adding content to a web-page with javascript. The problem is that
I'm working with a JFrame adding JPanel instances dynamically in the following way: private

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.