选择大的父元素属性 [英] Select grand parent element attribute

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

问题描述



我有这样的行:

p>

  var linkTitle = $(this).attr('title'); 

这是一个表单复选框,没有标题属性。然而,大父母li。我想选择grand parent title属性。这是可能吗?



结构如下:

  ; ul> 
< li>
< input>


解决方案

b
$ b

  $(this).parent()。attr('title'); 

或您也可以这样做。

  $(this).parents('li')。attr('title'); 


I'm not so sharp on jquery but am setting up an analytics implementation (Using Google Tag MAnager) that uses titles.

I have this line:

var linkTitle = $(this).attr('title');

The this in question is a form checkbox and it has no title attribute. The grand parent li, however, does. I'd like to select the grand parent title attribute. Is that possible?

The structure is like so:

<ul>
 <li>
  <input>

解决方案

you can try like this.

$(this).parent().attr('title');

or you can also do like this.

 $(this).parents('li').attr('title');

这篇关于选择大的父元素属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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