jQuery:在父div之外选择下一个div [英] jQuery: select next div outside of parent div

查看:92
本文介绍了jQuery:在父div之外选择下一个div的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,我觉得我缺少了一些非常简单的东西,但是这里有:

Ok, I feel like I"m missing something really simple but here goes:

此代码非常有效,完全符合我的要求.您单击该链接,然后显示下一个div(一个页面上大约有10个)

This code works great, exactly the way I want it to. You click the link and the next div is revealed (There are about 10 of these on a page)

    $('a.addtask').click(function(){
      $(this).next('.field').slideToggle();
    return false;
    });

  <div class="field">
   Some content
  </div>

  <a href="#" class="addtask">Add a task</a>

  <div class="field" style="display:none;">
    some other content
  </div>

但是我想要做的是像这样更改HTML(div内的链接):

What I want to do however is change the HTML like so (link inside the div):

<div class="field">
   Some content
   <a href="#" class="addtask">Add a task</a>
  </div>


  <div class="field" style="display:none;">
    some other content
  </div>

^^哪个无法正常工作.

^^Which doesn't work properly anymore.

要使这项工作有效,我需要在jquery中进行哪些更改?我已经搜索了一段时间,类似帖子中的许多解决方案似乎都没有用.

What do I need to change in my jquery to make this work? I've been googling for a while now and a number of solutions in similar posts dont seem to be working.

推荐答案

$(".addtask").parent().next(".field")应该可以工作

这篇关于jQuery:在父div之外选择下一个div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆