jquery - .closest .prev jquery 无法专注于上面的 A 标签

标签 jquery css

不确定为什么这不起作用,但我有:

https://jsfiddle.net/m9uqdx5y/

<div class="sectionContent">
  <span class="open"><a>top</a></span>
  <span class="closeEditorLink"><a>bottom</a></span>
</div>

    var $preDiv = $('.closeEditorLink');
    $($preDiv).click(function () {
        $($preDiv).closest('.sectionContent a').focus();
    });

我只需要关注上面的 A 标签。

最佳答案

.closeEditorLink 不是 .sectionContent a 的子项,因此 .closest(".sectionContent a") 什么也没有。

试试 .closest('.sectionContent').find('.open a').focus(); 代替。

关于jquery - .closest .prev jquery 无法专注于上面的 A 标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39858258/

相关文章:

当有属性 block 时,jquery + div 不会用 .hide() 正确隐藏?

javascript - 从当前样式表中获取所有类名的替代方法

html - 在剩余空间中水平居中最大宽度的 flexbox 元素

javascript - 如何从数组中分割指定数量的元素?

javascript - 匹配数组和返回值

php - 如何对齐 Bootstrap 缩略图

html - 同一个 li 标签中的两个超链接

html - 如何在标签内制作 CAKEPHP 单选按钮

javascript - jquery 创建的 data-* 有时无法解析

javascript - 在 jqplot 折线图中动态传递系列