获取包含特定类的第一个匹配祖先
我试图迭代到包含类“sys-form-row”的第一个祖先。
我可以使用以下命令获取包含 class="sys-form-row" 的行: objBack =
$('#txtMyBox2').parent().parent();
这看起来非常笨拙。我想做的是这样的:
$('#txtMyBox2').parents('.sys-form-row');
甚至 $('#txtMyBox2') .closest('.sys-form-row');
但是,如果应用额外的 div 嵌套,两者都会失败,并且我当前的方法并不总是有效。 任何帮助将不胜感激。
I am trying to iterate to the first ancestor containing the class ‘sys-form-row’.
I am able to get the row containing class="sys-form-row" using the following: objBack =
$('#txtMyBox2').parent().parent();
This seems incredibly clumsy. What I would like to do is something like this:
$('#txtMyBox2').parents('.sys-form-row');
or even $('#txtMyBox2').closest('.sys-form-row');
however both fail and my current approach will not always work if additional div nesting is applied.
Any help would be really appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果附加的嵌套 div 有任何特定的类,您可以使用最接近的来查找父级
If the additional nested div has any specific class you can use closest to find the parent
试试这个:
Try this: