Error
Error

Reputation: 153

Fetch the contents of a table row using javascript when a link is clicked

I have a dynamic table and in one of the attributes of that table I have edit link, I want to fetch the data adjacent to that link if that link is clicked.

enter image description here

For example if I click Edit on line number 2, I should be able to retrieve Demo User, demouser, [email protected] and User using javascript.

Upvotes: 0

Views: 33

Answers (1)

Robo Robok
Robo Robok

Reputation: 22673

The key is to access the row and then find elements inside that row:

$('.your-link').click(function () {
    const row = $(this).closest('tr');
    const whatever = row.find('.whatever').text();
})

Upvotes: 1

Related Questions