jquery找到第一个元素 [英] jquery find to get the first element

查看:98
本文介绍了jquery找到第一个元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写 $(this).closest('。comment')。find('form')。toggle('slow'); ,问题是孩子的每个表格都被切换了。我想只切换第一个表格。 html类似于下面的内容,这是一个链接

I am writing $(this).closest('.comment').find('form').toggle('slow'); and the problem is each of the forms in the child is being toggled. I would like only the first form to be toggled. the html is something like the below and this is the a link

<div comment>
<a href>
<form>
</form>
    <a href>
    <div comment>
    <form>
    </form>
    </div>
</div>


推荐答案

您可以使用

$(this).closest('.comment').find('form').eq(0).toggle('slow');

$(this).closest('.comment').find('form:first').toggle('slow');

这篇关于jquery找到第一个元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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