For whatever reason I have these classes called .main_sub1, .main_sub2 etc. Never mind why I can't have .main .sub.

Is there a way with jQuery, sort of in the way it is possible to do with attributes, to get the classes containing main?

推荐答案

使用$("[class^=main]")将 Select 类名starts with为"main"的所有元素.看一下jQuery docs about selectors,您可以使用很多其他变体,例如:

  • [class*=main] will select elements whose classname contains 'main'
  • [class~=main] will select elements whose classname has the word 'main' (delimited with spaces)
  • [class$=main]将 Select 类名ends in为"main"的元素

Jquery相关问答推荐

提交表单时运行自定义验证脚本

在 Bootstrap 3 中向工具提示添加换行符

如何使用 jQuery 禁用粘贴(Ctrl+V)?

如何在 jquery 中从这个日期减go 一周?

JQuery/Javascript:判断 var 是否存在

使用 jQuery 更改 CSS 类属性

如何使用 jQuery 重置 jquery Select 的 Select 选项?

jQuery Keypress 箭头键

javascript:检测滚动结束

子元素点击事件触发父点击事件

如何知道字体(@font-face)是否已经加载?

javascript 正则表达式用于包含至少 8 个字符、1 个数字、1 个大写和 1 个小写的密码

从附加元素获取 jQuery 对象的更简单方法

隐藏 div 但保留空白

使用 jQuery DataTables 时禁用第一列的自动排序

Url.Action 在我的 url 中放了一个 &,我该如何解决这个问题?

jQuery slideUp().remove() 在删除发生之前似乎没有显示 slideUp 动画

jQuery位置href

jQuery 发送字符串作为 POST 参数

如何获得两个日期对象之间的小时差?