Search code examples
jqueryclassparent

jQuery affect classes outside parent element


Is there a jQuery function to select all DOM elements of a certain class that are outside the parent(s) of an element selected with $(this)?

Thanks,

James


Solution

  • You can use .not() to exclude the ancestors (gotten via .parents()), like this:

    $(".class").not($(this).parents())