Reputation: 205
Confusing title... However I want to get the data-attr value of some td's which are in the same table as the button which triggers the event.
Here is the table, or rather the body of the table:
<tr class="reihe">
<td data-datum="@iiEntry.ccDatum">@iiEntry.ccEntryID</td>
<td class="size" data-firma="@iiEntry.ccBesucherFirma">@iiEntry.ccBesucherFirma</td>
<td class="size" data-name="@iiEntry.ccBesucherFirma">@iiEntry.ccBesucherName</td>
<td class="size" data-status="@iiEntry.ccStatus">@iiEntry.ccStatus</td>
<td class="size" data-ansprechpartner="@iiEntry.ccAnsprechpartner">@iiEntry.ccAnsprechpartner</td>
<td><button class="btn btn-default signin" id="[email protected]">Anmelden</button></td>
<td><button class="btn btn-default delete">Löschen</button></td>
</tr>
And the script which should handle all that:
$("[id^='signin']").click(function() {
var lCompleteRow = $(this).closest("tr");
var lFirma = $(lCompleteRow[0]).data("firma");
alert(lCompleteRow);
});
Now, I already tried a lot and with what I got now I can access the tr
but I can't figure out a way to get the value of the data attribute of the td
or I just get undefined
returned.
How can I solve this?
Upvotes: 0
Views: 6771
Reputation: 251
$(".signin").click(function() {
var lCompleteRow = $(this).closest("tr").children("td:eq(1)").attr('data-firma');
console.log(lCompleteRow);
});
Upvotes: 0
Reputation: 144699
lCompleteRow
refers to the tr
element. It doesn't have any data so the data
method returns undefined
. You should select the target cell before calling the data
method.
lCompleteRow.children('[data-firma]').data('firma');
Another option is:
$(this.parentNode).siblings('[data-firma]').data('firma');
Upvotes: 4