使用jQuery选择最接近的锚元素 [英] selecting closest anchor element using jquery

查看:88
本文介绍了使用jQuery选择最接近的锚元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有一个链接的表,如下所示

I have a table with one link as follows

 <td>
      <a href="#" class="topiclink">@item.Topic</a>
   </td>

我想选择@ item.topic的数据. 我尝试使用

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.

推荐答案

var val = $(this).text(); 

足以让你得到

这篇关于使用jQuery选择最接近的锚元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆