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

The Archive Base Latest Questions

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

I’m parsing XML and putting it in a simple table like this: function showData(message)

  • 0

I’m parsing XML and putting it in a simple table like this:

function showData(message) {
    var str = "<table border=1 class='editable'>";
    for (var i = 0; i < message.length; i++) {
        str += "<tr>" + "<td>" + message[i].id + "</td>" +
                       "<td>" + message[i].name + "</td>" +
                       "<td>" + message[i].url + "</td>" +
                       "<td>" + message[i].desc + "</td>" + 
                       "<td>" + "<a href='javascript:deleteRequest();' id=message[i].id>delete</a>" + "</td>" + "</tr>";
    }
    str += "</table>";
    return str;
}

I have an tag in the last column of my table and I’m trying to set the id of the tag, or be able to get it from my deleteRequest method so I can delete that entry in the table.

1) I’m not sure if I’m setting the id correctly for the tag.

2) I’m not sure how to get the id in my deleteRequest method for the selected tag, like a sender in iOS, or maybe to pass the id in as an argument to deleteRequest(). I’m not sure which method is better. I tried to do a simple alert(arguments[0]) to see what gets passed in this case, and I get undefined. So I’m kind of lost what to do as I’m just learning Javascript. Thanks.

  • 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-30T08:13:13+00:00Added an answer on May 30, 2026 at 8:13 am

    Try something like this for the line with the link in it:

    "<td>" + "<a href='javascript:deleteRequest(this);' id='" + message[i].id + "'>delete</a>" + "</td>" + "</tr>";
    
    // OR, without the extra + operations:
    "<td><a href='javascript:deleteRequest(this);' id='" + message[i].id + "'>delete</a></td></tr>";
    

    You weren’t concatenating the value from message[i].id into the string you are producing, you were including the string “message[i].id”. (Note that that line ends up looking similar to the four lines of code before it.)

    If you pass this as a parameter to your function, like deleteRequest(this) as shown above you can do this:

    function deleteRequest(el) {
       // el is the <a> that was clicked
       alert(el.id);    // displays the id from the row that was clicked
    }
    

    (Obviously the alert(el.id) is just an example of how to access the id property, you’ll do whatever you want with it at that point.)

    Note about terminology: Your question title was “Get id element of an tag” – id is an attribute, the link is an anchor element (or “a” element), and in your html markup the anchor element is defined with an <a> tag. (Similarly, “href” is an attribute.)

    EDIT: I just noticed you have your JS embedded within the href attribute. I’m not sure if that will work properly with the this keyword, but in any case a better way to do it is:

    <a href="#" onclick="deleteRequest(this); return false;">
    

    Or, within your code:

    "<td><a href='#' onclick='javascript:deleteRequest(this);return false;' id='" + message[i].id + "'>delete</a></td></tr>";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
For some reason, after submitting a string like this Jack’s Spindle from a text
I'm parsing an XML file, the creators of it stuck in a bunch social
I am doing a simple coin flipping experiment for class that involves flipping a
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I would like to count the length of a string with PHP. The string
this is what i have right now Drawing an RSS feed into the php,

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.