零零乙 2009-06-24 22:28 采纳率: 33.3%
浏览 686
已采纳

如何在 jQuery 中选择具有多个类的元素?

I want to select all the elements that have the two classes a and b.

<element class="a b">

So, only the elements that have both classes.

When I use $(".a, .b") it gives me the union, but I want the intersection.

转载于:https://stackoverflow.com/questions/1041344/how-can-i-select-an-element-with-multiple-classes-in-jquery

  • 写回答

11条回答 默认 最新

  • 叼花硬汉 2009-06-24 22:30
    关注

    If you want to match only elements with both classes (an intersection, like a logical AND), just write the selectors together without spaces in between:

    $('.a.b')
    

    So for a div element that has an ID of a with classes b and c, you would write:

    $('div#a.b.c')
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(10条)

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器