jQuery子元素的子元素 [英] jQuery child of clicked element
本文介绍了jQuery子元素的子元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个链接列表,其中链接了单击事件,我需要从子A链接中获取ID.因此,在下面的示例中,如果我单击第一个列表元素,则需要重新调整google.
I've got a list of links which have a click event attached to them, I need to get the ID from the child A link. So in the example below if I clicked the first list element I'd need google retuned.
我已经尝试过'$this a'
,但是不能完全弄清语法.
I've tried '$this a'
but can't quite work out the syntax.
$("ul li").click(function(event){
$("input").val($(this).html());
});
<ul>
<li><a href="http://www.google.com" id="google">Google</a>
</ul>
推荐答案
我看不到示例HTML,但
I don't see the sample HTML but
$(this).find('a:first').attr('id')
会这样做(如果不是您的意思,请修复 a:first 选择器)
would do it (fix a:first selector if it's not what you meant)
此是触发事件的元素
这篇关于jQuery子元素的子元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文