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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T00:30:21+00:00 2026-05-12T00:30:21+00:00

What is the best-practise way of Identifying dynamically generated element on page? Let me

  • 0

What is the best-practise way of Identifying dynamically generated element on page?

Let me explain. I have a list of elements, there can be as few or as many elements as the user defines, on a page. Each one of these corresponds to an item each with it’s own id. Now, the user has the ability to edit or delete these elements on the page and these operations are handled with jQuery. Each element comes with a link per operation they can action (i.e delete and edit).

Now a problem is knowing which element the user has selected. To deal with this I give each link the ID of the element as an ID attribute, which I then obtain using jQuery:

<a href="#" class="delete" id="<%= Model.elementID%>">Delete</a>

<script type="text/javascript">
    $(".delete").live("click", function (event) {
        event.preventDefault();
        var elementID = $(this).attr("id");
        //other code
    });
</script>

This is obviously far from ideal as it would mean many DOM elements could have the same ID. Alternatively I could create my own attribute such as elementID but I believe this breaks standards.

So what could you recommend. How can I identify dynamically generated elements on a page?

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

    I’ve done this quite a bit for my sites and my solution is a combination of where you started from and some of the comments:

    Use a naming convention, like “element_type:id:action”. So your example’s generated be “element:23:delete”. Then you can split() the .attr(“id”) that you’ve grabbed and determine what it is (“report” vs “folder”), the id, and what you want to do (“delete”, “edit”, “move”).

    This has worked out very well for me, and is very scalable.

    I’d keep the class, though, so that you can easily attach events via jquery.

    James

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

Sidebar

Related Questions

Is there a best-practice or common way in JavaScript to have class members as
Just looking for the best practise way of doing this. I have a table
is there any best practice way to replace a part of the default template.
what is the best practice or best way of passing form parameters from page
Is there a way in Cocoa that is currently considered best practice for creating
I'm curious as to the best-practise way to handle having something appear on every
What are the best way or method of best practise to ensure that a
is there a best practise to get values from a database in java? my
Is there a library or best-practice way of creating a menu with navigation links
I'm looking for a best practise way to handle incoming time series data. One

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.