views:

23

answers:

1

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

+2  A: 

$(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.

patrick dw
I got it, its using children(); Thanks for the knowledge
atif089
`$(this)` refers to the `.post` element that received the event. To access an descendant of `$(this)`, you could do `$(this).find('a')`. I'll update my answer.
patrick dw