Reputation: 1059
I have a table with one link as follows
<td>
<a href="#" class="topiclink">@item.Topic</a>
</td>
I want to select data of @item.topic. I tried using
$('.topiclink').click(function (e) {
var val = $(this).closest('a');
alert(val)
});
and many others but nothing seems working in this case.Thank for the help.
Upvotes: 3
Views: 2432
Reputation: 10714
A lot of errors in your code ! Your element is already a '.topiclink' class, so why do you want the closest element ? Just use $(this) to access your element. val() not return the html of the element, you should use $(this).html();
$('.topiclink').click(function (e) {
alert($(this).html());
}
Upvotes: 0
Reputation: 773
If you're trying to get the value '@item.Topic' on click of the anchor or any anchor, that is, you may use below code:
$('a').click( function () {
console.log($(this).text());
});
Upvotes: 2