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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T05:33:32+00:00 2026-06-16T05:33:32+00:00

I am using jQuery.ajax to read and render XML file into HTML. The below

  • 0

I am using jQuery.ajax to read and render XML file into HTML.

The below code generates a table of buttons for each data record in the XML:

$(xml).children('run').each(function() {
    var runname = $(this).children('name').text();

    buttonHtml = '<tr><td class="expbutton" id="runExpButton" onmousedown="myFunc(runname)">Click me</td></tr>';

    $('#Runs').append(buttonHtml);
});​

It’s not hard to see what I want to achieve here. But obviously it does not work.

My question is how do I achieve this in jQuery? If I use .live or .on methods I don’t have access to the local variable such as “runname”.

[EDIT]

Attempt on using jQuery.data():

$(xml).children('run').each(function() {
    var runname = $(this).children('name').text();

    buttonHtml = '<tr><td class="expbutton" id="runExpButton" onmousedown="myFunc(runname)">Click me</td></tr>';
    $('#runExpButton').data('runname', runname);
    $('#Runs').append(buttonHtml);
});​

$('#runExpButton').live('click',function() {
    alert($(this).data("runname"));
});

It does not seem to work? Only one of the buttons has the correct data value.

Because all the buttons have the same id, I suspect .data() doesn’t work with this?

  • 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-16T05:33:33+00:00Added an answer on June 16, 2026 at 5:33 am

    What I believe you are looking for is jQuery .data()

    You can store data for an html element and then pull that data in when the element is clicked.

    An example would be

    $(xml).children('run').each(function(index) {
        var runname = $(this).children('name').text();
        buttonHtml = '<tr><td class="expbutton" id="runExpButton'+index+'">Click me</td></tr>';
        $('#Runs').append(buttonHtml);
        $('#runExpButton'+index).data('runname', runname);
    });​
    
    $(document).on('click', '.expbutton', function(){
         alert($(this).data('runname'));
    });
    

    I edited your code to add unique IDs to each cell you are adding to the table.

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

Sidebar

Related Questions

So I'm using jQuery's AJAX function to read some XML for me and it's
How can I read and sign XML data (array of different sizes) using jQuery?
I can directly read the XML Feed using jQuery, but when I display the
How could I GET the information in an XML file and read it into
Asp.net September 2012 Release ajax toolkit combobox is read only when using jquery. Any
I am performing a simple AJAX() request using Jquery (Google hosted 1.7.1 jquery.min.js code)
I am using JQUERY .ajax() to send serialized form data to MySQL using PHP.
I'm having trouble using jQuery.ajax() to post a gist to Github. The gist is
I recently started using jQuery/AJAX for submitting data to my PHP API. Currently what
I'm using Jquery Ajax Form to upload files, which works well in Chrome and

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.