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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T22:09:19+00:00 2026-05-15T22:09:19+00:00

I have web layout, which can contains several links on it. Those links are

  • 0

I have web layout, which can contains several links on it. Those links are dynamically created, using AJAX functions. And it works ok.

But, I don’t know how can I work with those “dynamically created links” (ie. how to call some JS or jQuery function if I click on them). I guess that browser can not recognize them, since there are created after page is loaded.

Is there some function, that can “re-render” my page and elements on it?

Tnx in adv on your help!

  • 1 1 Answer
  • 2 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-15T22:09:19+00:00Added an answer on May 15, 2026 at 10:09 pm

    You can use the 2 following methods jQuery provides:

    The first one, is the .live() method, and the other is the .delegate() method.

    The usage of the first one is very simple:

    $(document).ready(function() {
        $("#dynamicElement").live("click", function() {
            //do something
        });
    }
    

    As you can see, the first argument is the event you want to bind, and the second is a function which handles the event. The way this works is not exactly like a “re-rendering”. The common way to do this ( $("#dynamicElement").click(...) or $("#dynamicElement").bind("click", ...) ) works by attaching the event handler of a determinate event to the DOM Element when the DOM has properly loaded ($(document).ready(...) ). Now, obviously, this won’t work with dynamically generated elements, because they’re not present when the DOM first loads.

    The way .live() works is, instead of attaching the vent handler to the DOM Element itself, it attaches it with the document element, taking advantage of the bubbling-up property of JS & DOM (When you click the dynamically generated element and no event handler is attached, it keeps looking to the top until it finds one).

    Sounds pretty neat, right? But there’s a little technical issue with this method, as I said, it attaches the event handler to the top of the DOM, so when you click the element, your browser has to transverse all over the DOM tree, until it finds the proper event handler. Process which is very inefficient, by the way. And here’s where appears the .delegate() method.

    Let’s assume the following HTML estructure:

    <html>
    <head>
    ...
    </head>
    <body>
        <div id="links-container">
            <!-- Here's where the dynamically generated content will be -->
        </div>
    </body>
    </html>
    

    So, with the .delegate() method, instead of binding the event handler to the top of the DOM, you just could attach it to a parent DOM Element. A DOM Element you’re sure it’s going to be somewhere up of the dynamically generated content in the DOM Tree. The closer to them, the better this will work. So, this should do the magic:

    $(document).ready(function() {
        $("#links-container").delegate("#dynamicElement", "click", function() {
            //do something
        });
    }
    

    This was kind of a long answer, but I like to explain the theory behind it haha.

    EDIT: You should correct your markup, it’s invalid because: 1) The anchors does not allow the use of a value attribute, and 2) You can’t have 2 or more tags with the same ID. Try this:

    <a class="removeLineItem" id="delete-1">Delete</a> 
    <a class="removeLineItem" id="delete-2">Delete</a> 
    <a class="removeLineItem" id="delete-3">Delete</a>
    

    And to determine which one of the anchors was clicked

    $(document).ready(function() {
        $("#links-container").delegate(".removeLineItem", "click", function() {
            var anchorClicked = $(this).attr("id"),
                valueClicked = anchorClicked.split("-")[1];    
        });
    }
    

    With that code, you will have stored in the anchorClicked variable the id of the link clicked, and in the valueClicked the number associated to the anchor.

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

Sidebar

Related Questions

I have a web page which has three <div> elements: Right_bar contains several layouts
I'm currently building a SmartGWT-based web application (using the Portlet Layout). So I have
I have a bunch of ASP.NET web pages (that have a standard layout) that
I have web service, which use integrated security in IIS. Now, I want to
I have web page in PHP which displays all records in a table. I
I have web page which is passing a querystring parameter to page 2: <a
I have web application written in java using Eclipse. It has just one servlet
I have web application which we deployed in a production . We have separate
I have web application of which major part is javascript. I request images from
I have an asp.net application which uses the web part framework to allow users

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.