admin管理员组文章数量:1334678
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.
$(".ui-icon-triangle-1-e").click(function () {
GetRuleData($(this).closest("a.tariff-link"));
});
An example of HTML would be like this:
<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>
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.
$(".ui-icon-triangle-1-e").click(function () {
GetRuleData($(this).closest("a.tariff-link"));
});
An example of HTML would be like this:
<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>
Share
Improve this question
asked Jun 28, 2012 at 19:07
VictorVictor
1,2717 gold badges23 silver badges43 bronze badges
2
-
4
Read the documentation on
.closest()
. It gets the closest parent, not sibling child or cousin. – Kevin B Commented Jun 28, 2012 at 19:09 - Closest beginning at the current element and progressing up through the DOM. – Ricardo Lohmann Commented Jun 28, 2012 at 19:09
2 Answers
Reset to default 10You need .siblings()
instead of .closest()
. The latter checks the current element and its ancestors but your a
is a sibling of the current element, not an ancestor.
If it's always the element right after the current element you could also use .next()
.
try:
GetRuleData($(this).next("a.tariff-link"));
本文标签: javascriptjquery closest() doesn39t workStack Overflow
版权声明:本文标题:javascript - jquery closest() doesn't work - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742378056a2463562.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论