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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T10:30:59+00:00 2026-06-09T10:30:59+00:00

I am learning some JQuery basics and am stumped on this particular situation. I

  • 0

I am learning some JQuery basics and am stumped on this particular situation. I have a basic table with a delete button at the end of each row and am trying to get my JQuery code to recognize the value of column 1 depending on which row I click the ‘Delete’ button on. It keeps giving me the value of the first row regardless of the row I am actually on.

Here is my code for the table:

     <table id="DemoTable">
        <thead><tr><th>Product</th><th>Price</th></tr></thead>
        <tr><td>Sirloin Steak 10 oz.</td><td>8.77</td><td><input type="submit" value="Delete" /></td></tr>
        <tr><td>Filet Mignon 8 oz.</td><td>14.50</td><td><input type="submit" value="Delete" /></td></tr>
        <tr><td>Redi-Grill 5 oz.</td><td>1.55</td><td><input type="submit" value="Delete" /></td></tr>
        <tr><td>San Marco Stuffed Shells</td><td>.35</td><td><input type="submit" value="Delete" /></td></tr>
        <tr><td>Sliced Cheese Yellow</td><td>.10</td><td><input type="submit" value="Delete" /></td></tr>
    </table>

And here is the JQuery section:

<script type="text/javascript">
  $(document).ready(function () {
    $('form').submit(function () {
        var itemName = $('td:nth-child(1)', this).html();
        return confirm('Are you sure you want to delete ' + itemName + '?');
    });
  });
</script>

Thanks for any help!

  • 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-09T10:31:01+00:00Added an answer on June 9, 2026 at 10:31 am

    Your code is running on the submit event of the form, so when you use this it is the form itself rather than being the particular button that was clicked. Try handling the click event on the delete buttons, because then you can get the td that is in the same row as the button:

    $('#DemoTable input[type="submit"]').click(function() {
       var itemName = $(this).closest("tr").children().eq(0).html();
       return confirm('Are you sure you want to delete ' + itemName + '?');
    });
    

    Demo: http://jsfiddle.net/nnnnnn/VxWUJ/

    Note though that when the form is then submitted you need to do something with the value to be deleted, e.g., put it in a hidden field within the form. You don’t show the rest of your form in the question, but it looks like the only form elements you have are the delete buttons.

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

Sidebar

Related Questions

I've just been learning some jQUery to get a basic image gallery going on
I'm learning javascript and jquery and have written a very basic script inside my
I'm still learning jQuery and would appreciate some pointers with this, as I think
I have never worked on jquery but after some googling and learning I have
I'm learning some basics about JQuery. When I learn about something, I always try
I'm learning jQuery and am about to write some pages using intensively that library.
Learning some VBA. So far, I've constructed this piece of code which should allow
I'm learning some file functions and hence have a doubt. I'm curious about why
i have done some learning on struts based on one project that i got.Now
When I was doing some self-learning on JQuery Ajax in Cakephp, I found out

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.