jquery 选择唯一项

标签 jquery traversal

我在选择 html 中的某个元素时遇到问题

当我单击“event_rsvp”类的链接时,我想使用“interested-status”类来影响下一个li中的span的HTML 我已经尝试过最接近的方式,尝试去见 parent ,我如何告诉一个人与另一个人交谈。

<li rel="101590"><span class="rsvp-status">Are You Going? –&nbsp;<a href="javascript:;" class="event_rsvp" rel="attending">RSVP</a></span></li>

<li rel="101590"><span class="interested-status"> <a href="javascript:;" class="event_likeit" rel="likeit"> Like It?</a></span></li>

重要 可能重要的是要提到这是一个循环,我需要它只影响单击的那个。

最佳答案

您正在考虑处理 jQuery 的 siblings() 选择器。在 在这种特定情况下,您需要使用 next() 来检索 LI 的下一个匹配同级。

$('.rsvp_status').click(function() {
    // get the next LI with matching class
    $(this).parents().next('.interested-status');
});

关于jquery 选择唯一项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1698499/

相关文章:

php - 根据条件将一个关联数组中的值添加到另一个关联数组中

c++ - 二叉树C++的层序遍历

jquery - 添加类到父级(LI)

algorithm - 二叉搜索树中序遍历算法的时间分析

jquery - 使用 connectwith 进行多重遏制

javascript - 显示与其他 div 的属性匹配的 div 值

javascript - 在javascript中通过类名选择元素

c - C语言中如何遍历二维数组对角线?

jquery - 克隆一个包含 "customized"jQueryUI datePicker 的 div

jQuery :contains - exclude matching text in descendants