What JQuery selector excludes items with a parent that matches a given selector?

前端 未结 7 824
Happy的楠姐
Happy的楠姐 2020-12-02 16:39

I have

var $set = $(\'.foo,.bar\').filter(
    function() {return $(this).parents(\'.baz\').length < 1;});

as a way to select all the el

7条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-02 17:11

    The selector chaos gives should work:

    $('.foo:not(.baz .foo),.bar:not(.baz .bar)')
    

    Just wanted to give you a tip about an extension to FireBug called FireFinder that you can use to test your css/jquery selectors.

    From the website: Firefinder is an extension to Firebug (in Firefox) and offers the functionality to, in a quick way, find HTML elements matching chosen CSS selector(s) or XPath expression. It allows you to instantly test your CSS selectors in the page while seeing the content at the same time, and matching elements will be highlighted.

提交回复
热议问题