开发者

jQuery filter() traversing doesnt seems to work?

I dont know what is the problem with this ?

$('.post').live('开发者_开发问答mouseenter mouseleave', function() {  
         $(this).filter('anything here,a,div,.class,#id').toggleClass('hidden');
    });

where as this works fine.

$('.post').live('mouseenter mouseleave', function() {  
         $(this).toggleClass('hidden');
    });

There is an anchor which I would like to show on mouse hover. Similar to Facebook


$(this) refers to your .post element.

.filter() removes anything that does not match the selector.

So in your given example if the .post element is not one of the following

'anything here,a,div,.class,#id'

it gets filtered out.

.filter() doesn't traverse. It takes a jQuery set and reduces it to the elements that match the selector given.

http://api.jquery.com/filter/


EDIT:

There are lots of ways to traverse in jQuery.

http://api.jquery.com/category/traversing/

To get all the a elements that are descendants of the .post element that received the event, you could do:

$(this).find('a');

Which traversal method to use will depend on your situation.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜