jQuery包含 [英] jQuery contains

查看:63
本文介绍了jQuery包含的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法获得与包含语句匹配的最深元素?

Is there a way to get the deepest element matching a contains statement?

基本上,如果我有嵌套的div,我希望最后一个元素而不是父元素:

Basicly if I have nested divs, I want the last element not the parent element:

<div id="hayStack">
  <div id="needle">Needle</div>
</div>

$("div:contains('Needle')")返回hayStack div.

$("div:contains('Needle')") is returning the hayStack div.

到目前为止,我唯一想出的解决方案是用.not显式排除父div的ID.

The only solution I have come up with so far is explicitly exlcuding parent divs by their id with .not

推荐答案

添加:last将返回最深/最后一个div(将立即封装您要搜索的内容的

Adding :last will return the deepest/last div (the one immedietly encapsulating the content you are searching for

$("div:contains('Needle'):last")

这篇关于jQuery包含的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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