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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T06:29:38+00:00 2026-06-07T06:29:38+00:00

I have multiple dynamically created anchor tags that work as buttons. When any of

  • 0

I have multiple dynamically created anchor tags that work as buttons. When any of these buttons are clicked, I want to call a single javascript function that sits in another file, which will do the rest of the fun work. My problem is that I cannot properly call the function via the ‘onclick’ event, so I am trying to find a way around it but it’s just not so simple for me.

I have tried many different ways so I understand a few limitations with this approach:

Standard HTML anchor with Javascript:

<a href=#" onclick="doSomething(parameter1, parameter2, ...);">Button</a>

This is not going to help because there are synchronization issues and I have found that href will be chosen above on click almost always I have found. I actually would love this way to work, if you know any workarounds here then please let me know.

Binding via JQuery:

$(document).ready(function() {
     $("#button_id").click(function() {
         doSomething(parameter1, parameter2, ...);
     });
});

My issue with binding is that when the page is loaded, I have a function that gets the data from the database and displays it in a list. Each list element has a button, which ‘on click’ will call a javascript function, passing it parameters according to whatever data I need to give it from the list element, and it then will do something.

I understand that in order for Binding to work well, each button should have its own ID so that its easy to associate them with the Binding method. However, I am not sure how to tell the the .click function how many ID’s I have, nor how to give it these parameters (unless I capture them via button ID by calling other JS functions).

Any suggestions/ideas are highly appreciated!

EDIT:
How do I go about adding the button_data to the parameters of the ‘doSomething(parameter);’ function?

list_element = '<span class="ui-li-count" data-mini="true">' + button_data + '<a href="#" class="my_button">Button</a>';</span>

Please remember this data is obtained dynamically from the database and posted onto the site when the page is first loaded.

  • 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-07T06:29:40+00:00Added an answer on June 7, 2026 at 6:29 am

    There is no need to use an id for this. That’s the opposite of what you need to be doing since you are giving a group of element identical functionality. Instead, you should be giving them a class to group them:

    <a href=#" class="my-button">Button</a>
    

    And the JavaScript:

    $(document).ready(function() {
         $('body').on('click', '.my-button', function() {
             doSomething(parameter1, parameter2, ...);
         });
    });
    

    This will bind the click event to all .my-button elements, even ones that you haven’t created yet. Replace body with the parent element that contains all of the buttons to make this work a bit faster.

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

Sidebar

Related Questions

I have items and buttons that are created dynamically and I want to show
I have a form with multiple textboxes which are created dynamically, now all these
I have multiple asp:button that I created dynamically with jQuery. For each of them,
I have multiple (dynamically created) controls in a grid (labels, buttons), and one storyboard!
I have a noob-question, that might be similar to Dynamically create multiple instances of
I have ToggleButtons that are dynamically created based on my datasource. I would like
Basically I have a set of checkboxes that are dynamically created from view data
I have a very dynamic web app that is dynamically created controls at run-time.
Problem is that application closes without any error, VS stays opened. I have multiple
I want to have a single event listener for multiple events and depending on

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.