Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8840699
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:31:27+00:00 2026-06-14T10:31:27+00:00

I have a carousel object, with images and a pager. The problem is I

  • 0

I have a carousel object, with images and a pager. The problem is I can’t set the onClick to the pager. I’m obviously missing something here but I don’t know what.

The error when I click in a pager item is:

Uncaught TypeError: Object #<HTMLDivElement> has no method 'scrollCarouselTo'

I set my onclick

    carouselDots.on('click',function(){  
        this.scrollCarouselTo(1,5);   // <-- problem lies here, how can i call this method?
    });

and the scrollTo method

this.scrollCarouselTo=function(dotIndex, numDots)
    {       
        //H_SCROLL.scrollToElement("#carouselItem"+dotIndex, 300);
        H_SCROLL.scrollToPage(dotIndex, 0 , 300);
        this.highlightCarouselDot(dotIndex, numDots);
    }

Last, on my HTML file this is how I set it:

var tempCarousel = new Carousel();
tempCarousel.initialize(params,cont,scrollContainer);

My Carousel class: (parts of it that i think are relevant)

function Carousel() {

var container;
var pager;
var opt;
var thisCarousel;

//render the correct number of dots and highlight the indexed one
this.highlightCarouselDot=function(dotIndex, numDots)
    {       
        var ui_str="";
        console.log("numDots" + numDots);
        for (var i=0;i<numDots;i++)
        {
            if (i==dotIndex)
                ui_str+='<div class="carouselDot selected" id="carouselDot'+i+'"></div>';
            else
                ui_str+='<div class="carouselDot" id="carouselDot'+i+'"></div>';
        }

        console.log(ui_str);
        console.log(pager);
        pager.html(ui_str);

        var carouselDots = $(pager.selector + " .carouselDot");
        var dotSelected = $(pager.selector + " .selected");
        carouselDots.css('background',opt.pagerImage);
        carouselDots.width(opt.pagerSize);
        carouselDots.height(opt.pagerSize);
        carouselDots.on('click',function(){  //replace with touch
            this.scrollCarouselTo(0,5);
        });
        dotSelected.css('background',opt.pagerSelectedImage);

    }

    this.scrollCarouselTo=function(dotIndex, numDots)
    {       
        //H_SCROLL.scrollToElement("#carouselItem"+dotIndex, 300);
        H_SCROLL.scrollToPage(dotIndex, 0 , 300);
        this.highlightCarouselDot(dotIndex, numDots);
    }

}

Thank you!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T10:31:28+00:00Added an answer on June 14, 2026 at 10:31 am

    You are having trouble understanding where the scope is changing in your code. Yes this refers to the object you are in, but when you assign an event handler such as onclick, that function is run in the scope of the UI element that was clicked. This means that in your onclick code, this refers to the html object that was clicked, and not the highlightCarouselDot object.

    One common solution to this problem is to use an extra variable to store the value of this.

    var self = this;
    

    at the start of your object, that way you can refer to self within your event handlers when you want to refer to the outside object.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a carousel that will contain images with the same width but different
I have a scrolling carousel of images and captions that interact separately but coordinate.
I have a carousel with images but the images appear to the left of
I have a problem with my carousel. I've searched for similar questions. But found
I have the following problem: I am creating a simple plugin jquery carousel, to
I have a series of images that get loaded for a carousel, and it
I have remove some item from the list of the BxSlider carousel. But when
I have played around and implemented JQuery cycle to create a carousel with images,
Sorry If something like this has already been asked, but I can't find exactly
I have a carousel that I can change the location of with an integer

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.