获取子元素的属性 [英] Get attribute of child element
本文介绍了获取子元素的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我有以下标记:
< p =类头小时>
< A HREF =JavaScript的:无效(0)级=之类的sortcat =小时>
营业时间&安培; NBSP;<跨度类=imgholdersortcat =时间>&安培; NBSP;< / SPAN>
&所述; / A>
&所述; / P>
我如何能够针对<跨度>
锚标签内的标签?还有其他5个类似的< P>
标记条目,每个条目为 sortcat =
我已经尝试了各种各样的事情,没有运气。
感谢
解决方案
$(排序)。点击(函数(){
VAR的猫= $(本)。儿童(跨越)ATTR(sortcat);
//做一些与sortcat
});
If I have the following markup:
<p class="header hours">
<a href="javascript:void(0)" class="sort" sortcat="hours">
Hours <span class="imgholder" sortcat="hours"> </span>
</a>
</p>
How can I target the <span>
tag within the anchor tag? There are five other similar <p>
tag entries, each with a different value for sortcat=
I've tried a variety of things with no luck.
Thanks
解决方案
$(".sort").click(function(){
var cat = $(this).children("span").attr("sortcat");
//do something with the sortcat
});
这篇关于获取子元素的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文