[英]jquery closest() doesn't work
I am trying to grab the closest link with the class a.tariff-link
and send it to a method, but looks like closest()
cannot find it because it's always passing an undefined element. 我试图抓住与类
a.tariff-link
最近的链接并将其发送到方法,但看起来像a.tariff-link
closest()
找不到它,因为它总是传递一个未定义的元素。
$(".ui-icon-triangle-1-e").click(function () {
GetRuleData($(this).closest("a.tariff-link"));
});
An example of HTML would be like this: HTML的一个例子是这样的:
<h3 class="ui-accordion-header ui-helper-reset ui-state-default ui-corner-all" role="tab" aria-expanded="false" tabindex="-1">
<span class="ui-icon ui-icon-triangle-1-e"></span>
<a id="41965" class="tariff-link" href="#" tabindex="-1">
</h3>
You need .siblings()
instead of .closest()
. 你需要
.siblings()
而不是.closest()
。 The latter checks the current element and its ancestors but your a
is a sibling of the current element, not an ancestor. 后者检查当前元素及其祖先,但你的
a
是当前元素的兄弟 ,而不是祖先。
If it's always the element right after the current element you could also use .next()
. 如果它始终是当前元素之后的元素,您也可以使用
.next()
。
尝试:
GetRuleData($(this).next("a.tariff-link"));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.