javascript - 查找类包含文本字符串 JQuery 的跨度

标签 javascript jquery

我正在使用 JQuery 查找一个 span 元素,该元素包含 class 中的文本字符串,但也可能包含其他文本。

var not_breaks = element.filter("span.this_text");

这适用于 class="this_text" 但不适用于 class="this_text_and_more_text" 的跨度 - 我需要搜索两者。

最佳答案

在这种情况下,您可以使用 Attribute Contains选择器:

var not_breaks = element.filter("span[class*='this_text']");

您还可以使用 Attribute Starts With选择器,但请注意,这保证在元素上只有一个类时有效:

var not_breaks = element.filter("span[class^='this_text']");

关于javascript - 查找类包含文本字符串 JQuery 的跨度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42505186/

相关文章:

javascript - 使用 jquery 替换部分 href

javascript - 在 IE 中以编程方式隐藏弹出窗口

javascript - 在javascript中,循环中的函数无法访问循环范围变量

javascript - 在windows10中安装Chilkat-11后出错

javascript - 隐藏在其他元素后面的 Bootstrap 下拉菜单

javascript - 排序列表但保留 CSS 标记

javascript - 将 HTML 页面推到一侧

jquery - jQuery 中的属性网格

javascript - div 的 css 高度 100% 的问题

javascript - Firefox 喜欢检查元素