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

  • Home
  • SEARCH
  • 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 6390807
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T03:35:37+00:00 2026-05-25T03:35:37+00:00

How to get the value of cell in a table when the user click

  • 0

How to get the value of cell in a table when the user click on the next cell?

<table id="registrarsTable">

<c:forEach items="${requestScope.AllUsers}" var="user" varStatus="loop">
    <tr class="userRow">
        <td class="numberWidth">${loop.index + 1}</td>
        <td class="nameWidth user" id="${user.userno}">${user.fullName}</td>
        <td>

         <button name="DeactivateBtn"  id="deactivate" class="deactivate btn">deactivate</button>

        </td>
    </tr>
</c:forEach>

in jquery I want to get the value of attribute “id” from second td when user click on deactivate button.

I make like this

var userNo = $('td.user', $(this).parents(".userRow")).attr('id');

and like this

      var userNo = $($(this).parent(".userRow") > "td").attr("id");

and no one works!

  • 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-25T03:35:38+00:00Added an answer on May 25, 2026 at 3:35 am
    $('#deactivate').click(function() {
        var userNo = $(this).parent().prevAll('td.user').attr('id');
    });
    

    From the button (which is this), traverse up to the parent (the <td> containing the deactivate button). Then, to the previous sibling <td> with the class user, and get the id attribute.

    Alternatively, if you want to avoid relying on the fact the the deactivate button is in a <td> after the user name’s <td>, you can do this:

    $('#deactivate').click(function() {
        var userNo = $(this).closest('tr').find('td.user').attr('id');
    });
    

    Which finds the parent <tr> with closest and then the <td class="user"> with find.

    Working example: http://jsfiddle.net/FishBasketGordo/Bk6ML/

    API References:

    • parent() – http://api.jquery.com/parent
    • prevAll() – http://api.jquery.com/prevAll
    • closest() – http://api.jquery.com/closest
    • find() – http://api.jquery.com/find
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I click a link in a table cell. I need to get the value
I am trying to work out how to get the value of table cell
I am trying to get the value of a table cell. For example <table
I am trying to get the value of a cell in a table view
I am trying to get the text value of a table cell relative to
I'm attempting to get the cell value from a gridview but running into a
How can i get value in <tr cost=xx.xx> if i click on some button
I face a problem when I try to get value from primary table in
I'm am attempting to get the value of one input in a table row
I've got a table and want to get an array of cell values which

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.