Joshc
Joshc

Reputation: 3853

jquery opposite of $(this)

Is it possible to perform the reverse action of $(this)?

So instead of gettin the this element, it gets everything matching .sb-popular-thumb a but excluding $(this)?

See code below of example. I have marked $(this) with $(reverse) so you can see what I am trying to achieve.

$('.sb-popular-thumb a').hover(
  function () {

    $('.sb-popular').stop().animate({
        height : '168px'                    
    }, 200);

    $(this).siblings('.sb-popular-thumb-title').show();

    $(reverse).siblings('.sb-popular-thumb-overlay').stop().fadeIn(200);

  },
  function () {

    $('.sb-popular').stop().animate({
        height : '140px'                    
    }, 200);

    $(this).siblings('.sb-popular-thumb-title').hide();

    $(reverse).siblings('.sb-popular-thumb-overlay').stop().fadeOut(200);

});

Upvotes: 4

Views: 2655

Answers (3)

Nick
Nick

Reputation: 6025

.not() excludes whatever you specify from your search.

So .not(this) excludes this.

Upvotes: 2

Pavel Staselun
Pavel Staselun

Reputation: 2010

This will imitate your 'reverse'

$('.sb-popular-thumb a').not($(this));

Upvotes: 4

adeneo
adeneo

Reputation: 318232

just use :

$('.sb-popular-thumb a').not(this)
                        .siblings('.sb-popular-thumb-overlay')
                        .stop()
                        .fadeIn(200);

It will get all the <a> elements within that class except this.

siblings() will do almost the same, but will only get sibling elements (duh) ?

Upvotes: 8

Related Questions