is there a way to get the intersect of selectors in jQuery

This question already has an answer here:

  • How can I select an element with multiple classes in jQuery? 10 answers

  • You can do

    $(".class1.class2")
    

    But I actally don't get what your fiddle has to do do with that. What are you trying to achieve?


    For a terrible solution that still works...

    $('.class1').filter('.class2');
    

    or

    $('.class2').filter('.class1');
    

    Note, the $('.class1.class2') selector is unquestionably the fastest solution. But if any people who see this answer who never knew what filter() was, now they have a decent grasp, and may be able to expand on that logic.

    Consider if someone asks "How do I select an element with ID whatever in jQuery?" Obviously, the fastest/most obvious answer is $('#id') . But answers such as $('*[id="' + id + '"]') provide alternative insight which may or may not be more useful than the obvious answer itself.

    链接地址: http://www.djcxy.com/p/83088.html

    上一篇: 从活动div中移除子类

    下一篇: 有没有办法让jQuery中的选择器相交