No problem, Matt.
BTW I'm sure you're aware that you can shorten...
if (o.parents().filter('div.unwantedclass').size()==0) { ... }
...to just
if (o.parents('div.unwantedclass').size()==0) { ... }
Matt Kruse-2 wrote:
>
>
> On Oct 2, 6:09 pm, Wizzud <[EMAIL PROTECTED]> wrote:
>> No, you can't check for parent conditions with is(). You can test
>> descendants
>> to a certain extent, but not parents.
>> The same goes for filter() - unless you use filter(function), in which
>> case
>> you do more or less what you like!
>> Also, using hierarchical selectors as filters won't work - they're
>> selectors, not filters.
>
> Ah - is the distinction made somewhere that I missed? Since "filters"
> are just a subset of the "selectors" it wasn't clear to me which types
> of expressions would work.
>
>> The third of your filter() tests ...
>> alert ( $('div').filter('div:not(.test) div').size() ); // Alerts 3
>> ... is treating the filter as 2 separate filters and adding the results,
>> eg
>> filter('div:not(.test)') + filter('div').
>
> Which is fine, I guess that functionality is acceptable as long as I
> understand that "filters" are different than "selectors". I just won't
> use that syntax and expect the results I wanted. :)
>
>> Is there a better way than...?
>> if (o.parents().filter('div.unwantedclass').size()==0) { ... }
>> It really depends on what you're using the 'o' collection for. The
>> obvious
>> alternative is not to put into 'o' anything that has a parent of class
>> 'unwanted' to start with, eg o = $('div:not(.unwantedclass)>*');
>
> Unfortunately I'm doing this check on an event handler and checking on
> what kind of element is clicked to determine what to do. Due to the
> size of the page, using selectors on page load to attach the correct
> event actions caused way too much slow down (over 10 seconds, page is
>> 400k from an internal webapp). So I'm catching the event at the
> container and then determining which element was clicked so I can take
> appropriate action.
>
>> If you can't do that, then there's nothing wrong with what you have, but
>> a
>> filter alternative (>=v1.2) could be...
>> o.filter(function(){return !$(this).parent().is('unwantedclass');});
>
> True, but I'm needing to checking for the class on any element in the
> parent chain, not just the immediate parent. So I guess the way I'm
> doing it will suffice. Thanks for your help!
>
> Matt Kruse
>
>
>
>
>
--
View this message in context:
http://www.nabble.com/.is%28%29-cannot-check-against-the-parent-chain--tf4556009s27240.html#a13014240
Sent from the jQuery General Discussion mailing list archive at Nabble.com.