jQuery选择具有多个类的元素 [英] jQuery select elements with multiple classes

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

问题描述

我需要选择包含多个类的所有元素。类名无关紧要,我只需要选择两个或更多的元素。

I need to select all elements that contain multiple classes. The class names don't matter, I just need to select any elements with two or more.

jQuery选择器会是什么样的?

What would the jQuery selector for that look like?

推荐答案

这应该选择具有两个以上类别的所有元素。

This should select all elements with more than two classes.

$('*').filter(function() {
  return this.className.trim().split(/\s+/).length > 1;
}).foo('bar');

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

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