2

I have a table in HTML that holds names, addresses and phone numbers.

In each row for that table, there is a link you can select that opens up a popover. When a popover is selected, I would like to store the name for that specific row. The class associated with a name is

<td class="du-orl-1"> Daniel </td>

I am trying to store that name in a class via Javascript but this just seems to store the whole array of data rather than the specific element:

var objectId = $(".du-orl-1").html($(this).html());

Any ideas on what I am doing wrong?

3
  • What does "this" means in your context? Commented Jul 14, 2014 at 2:58
  • It sounds like your interaction event is on the <tr> or <table> element and not on the <td> element. But, like Foca suggests, providing what the this in your code is would be helpful, as you want the this to be the <td> in question. Commented Jul 14, 2014 at 3:02
  • +1 for clear explanation and current markup and jQuery code. Commented Jul 14, 2014 at 3:18

2 Answers 2

1

The following jQuery should be helpful:

var objectId = $(this).closest('tr').children('td.du-orl-1').text();

Should give you the name on the row where the link was clicked.

Note: this refers to the anchor element (link) that was clicked; therefore this piece of code should be inside the click handler.

Sign up to request clarification or add additional context in comments.

Comments

0
var objectId = $("#myTable .du-orl-1").text();

or this :

var objectId = $("#myTable").find(".du-orl-1").text();

First try to add id of your table, and next to it your td class

1 Comment

This returns all names in my table rather than the one selected.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.