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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:48:12+00:00 2026-05-31T13:48:12+00:00

I have a simple table like this <table id=tempTable> <tbody> <tr id=row_01> <td> <button

  • 0

I have a simple table like this

<table id="tempTable">
    <tbody>
        <tr id="row_01">
            <td>
                <button onclick="btnclick(this);" >Save Row</button>
            </td>
        </tr>
        <tr id="row_02">
            <td>
                <button onclick="btnclick(this);" >Save Row</button>
            </td>
        </tr>
    </tbody>
</table>

function btnclick(e) {
    var currentRow = $(e).parent().parent();
    alert(currentRow.id);
}

I want to determine which row where the button clicked was placed. So I use some jquery method in btnclick() as you see abow. But sometime I don’t know how deep level the button was placed in row (), so Im looking for a way to get an ancestor by tag <tr> of a element.

Anybody help me, 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-31T13:48:14+00:00Added an answer on May 31, 2026 at 1:48 pm

    Try this :

    function btnclick(e) {
        var currentRow = $(e).closest('tr');
        alert(currentRow.id);
    }
    

    The closest() function will return the closest ancestor referenced by its selector. In this case the selector is simple a <tr> element.

    Taken from the jQuery docs :

    .closest( selector )

    Get the first element that matches the selector, beginning at the current element and progressing up through the DOM tree.


    A better method could be used if you change your HTML a little bit. If you placed the same class on each of your buttons.
    Eg :

    <td>
      <button class="myBtnClass" >Save Row</button>
    </td>
    

    Then your jQuery would look like this :

    $(".myBtnClass").on('click',function(){
        var currentRow = $(this).closest('tr');
        alert(currentRow.attr('id'));
    });
    

    This function will capture a click on any element with the .myBtnClass class.

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

Sidebar

Related Questions

I have very simple select like this: SELECT * FROM table WHERE column1 IN
let's imagine that i have a simple table like this: id - record id
Suppose I have a simple table, like this: Smith | Select Jones | Select
I have a simple table like following: class SnookerCurrentInfo extends Doctrine_Record { public function
I have a simple table ( Person_ ) like this: ID_ EN-EN_ FR-FR_ 1
I have a simple html table like this: <table> <thead> <tr><th>Column 1</th><th>Column 2</th></tr> </thead>
I have a simple table structure like this. What I would like to do
I have a very simple table called genre , which looks like this: GENRE
Suppose I have a simple MySQL table that looks like this: CREATE TABLE `my_table`
I have a simple MySQL table like this: create table `users`( `id` int(5) NOT

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.