This is the expected behavior. The selector '.myClass a' describes an A tag
being a descendant of a tag with the class myClass. is() doesn't work on a
relationship as the result is ambiguous. To check if this element is an A
tag that is a descendant of of a tag with class myClass, maybe try:
if($(this).filter('a').parents('.myClass').length > 0) {...}
Or, in your case:
if($(target).is('a')) {
if($(target).parents('.myClass').length > 0) {
}
if($(target).parents('.myOtherClass').length > 0) {
}
}
Or, if you just want to check if this is a child of an element with a
particular class, you could do:
var $parent = $(target).parent();
if($parent.is('.myClass')) {...}
if($parent.is('.myOtherClass')) {...}
--Erik
On 9/26/07, duff <[EMAIL PROTECTED]> wrote:
>
>
> Hi all,
>
> I have started to use Jquery a couple month ago, and i really love the
> framework.
>
> I am currently working on an event delegation plugin, attaching
> generic event to the document and applying filters to the target
> element to determine if an event should be applied.
>
> I have however noticed some weird behavior for the .is() and .filter()
> function :
>
> I am using the latest jquery version 1.2.1 and am having some troubles
> with the filter function.
>
> If you use filter with an expression containing a space ( '.myClass a'
> for example), nothing is filtered at all.
>
> $('*').filter('.myClass a' ); returns all the nodes on the page.
>
>
> Is it the expected behaviour ? Is there other ways to efficiently
> check if a given node matches a given rule ?
>
> document.addEventListener('click',
> function(target){
> if $(target).is('.myClass
> a'){
> //do sth
> }
> if
> $(target).is('.myOtherClass a'){
> //do sth else
> }
> }
> );
>
> Thanks
>
>