问题标签 [closest]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
jquery - .addClass 基于包含在两个表中的跨度
我正在尝试向表中添加一个类。
<table>
> <tbody>
> <tr>
> <td>
> <table>
> <tbody>
> <tr>
> <td>
><span class="subcategory">
所以基本上我想根据 span.subcategory 在初始表中添加一个类。我有这个:
但它只进入第二张桌子。
jquery - jQuery Closest() 不起作用
有人可以解释一下为什么要替换以下内容
和
不工作??
javascript - jquery根据id匹配元素
我是 jquery 的菜鸟。卡住了,希望能得到一些帮助。目前正在构建一个从特定页面获取数据的工具。页面如下所示:
下面是jquery的一个片段:
我正在尝试仅从<tr>
ID 为 parent0 和 child0 的块中捕获所有数据。
在其当前工作状态下,该工具将两个表中的所有数据作为文本捕获。理想情况下,我希望能够分别捕获所有<TR>
块,将它们放在一个数组中,然后我可以对其进行迭代。
jquery - div 父级内最近的输入
如果行中的其他单元格之一具有值,我正在尝试获取表行中一个输入的值。这里的目标是,如果用户在行中输入收到的钱,那么需要一个收到日期。因此,在提交时,我想查看所有行并检查当前单元格中的条目,然后检查日期单元格中的日期。付款条目不止一行。这是HTML:
这是我正在使用的 jQuery(尚未添加对 'this' 中的值的检查),以查看我是否得到了预期的结果。可悲的是,我得到“未定义”:
我想我理解了去父级然后找到你正在寻找的元素的概念。显然不是?感谢您的出色帮助!
jquery - Jquery Closest and Parents Not Working with Input and Nested Divs
I have hidden Divs with ".display-link" classes that are two levels up from an input box. When an input (checkbox) is clicked, it should display the hidden link in the parent's previous sibling's wrapper.
Or another way to say it is, when an input checkbox is clicked it should find the previous div with the class .display-link and show() that.
I am having trouble traversing the elements to reach this div with this class. It should only display the one, previous div.
I need to go out of the collapsible div and into the accordion-button div down to the display-link div.
javascript - jQuery a solution between children() and find(): anything that looks like closest()?
Based on the different answers received, the only solution using jQuery without implementing our own selector function is a basic selector with ":first" or followed by ".eq(0)" for jQuery.
I wanted to know if their were any kind of max depth option or a function like "get only the first result then return it" but it seems it's not available in jQuery since even :first in the selector does not seem to be faster that a call to .eq(0) Thanks for all the comments.
Original post:
I'm wondering if a function like "closest" is available for the children elements.
Let's say I have an html structure like that:
div.container > [* some elements, I can't use children()] > div.sub1 > div.sub2 > div.sub1 > [other various children elements]
If I want the first div.sub1 I'm doing something like:
The problem is that we cannot specify a "max depth" so it will be searched in ALL the children. I see it as a performance issue.
I'm talking about "max depth" because I could list the possibles selectors cases but it would be a long list, about 6-10 items depending on the case.
Anyone has a solution for this?
Thank you
jquery - 无法让最接近()和查找()工作
无法制作closest()
和find()
工作:
HTML
当我按下删除收藏夹时,它会隐藏一个链接但show()
不起作用,find()
方法相同。HTML 源代码中重复的 HTML 代码不能全部包含在内。
jquery - 获取上一个 ID 值表单 input="text"
我可以找到一种方法来获取 id =“ DropDownListA ”。但我必须通过使用它来获取 id-value
不知何故$(this).closest('input').attr('id')
不工作
jquery - jQuery FIND div 本地到单击的按钮
我正在尝试找到位于我单击的按钮附近的 DIV,但似乎无法找到它...代码如下。基本上我使用最接近或查找或上一个孩子或父母似乎没有找到“.tweetButtonOverlayWrapper”DIV来根据jQuery调用切换类......任何想法我做错了什么???
查询:
HTML:
jquery - jQuery中的链式选择器
我有一个包含许多表格的 Rails 表单。其中一个表有一个感兴趣的下拉元素,可以通过其 id 访问,如下所示:
我正在根据其中选择的值显示/隐藏另一个元素,这没问题。麻烦是:元素的表头行有我需要显示/隐藏的“th”元素。我可以像这样访问父表元素:
但是,我试图通过给它一个“price_term”类来定位需要隐藏的标题元素(th)。所以我试图进一步缩小最接近这个元素的元素,如下所示:
但是,这不起作用。有没有办法可以定位这个标题元素?