Philippe Mongeau
Philippe Mongeau

Reputation: 158

Scrolling to the previous div in jQuery

I'm using the scrollTo plugin for jQuery on a website. I made a vertical scrolling div wher I can scroll to different div by clicking on buttons. And now I need to make a back button to return to the previous div.

what I want is the opposite of

this.next()

I tried

this.prev()

but it doesn't work.

$('#tabs').click
(
    function()
    {
        $('#wrapper').scrollTo(this.prev(), 'medium')
    }
);

Upvotes: 1

Views: 2121

Answers (2)

Jake McGraw
Jake McGraw

Reputation: 56106

Try:

$('#tabs').click
(
    function()
    {
        $('#wrapper').scrollTo($(this).prev(), 'medium')
    }
);

In events this represents the DOM element, not the jQuery object.

Upvotes: 1

Shog9
Shog9

Reputation: 159618

this is a raw element reference - you'll need to wrap it in a jQuery object before you can use jQuery methods like prev(): $(this).prev()

Upvotes: 1

Related Questions