How do I get the 'Flexslider' current image number into a variable which I can use in a function?

byronyasgur picture byronyasgur · Jun 26, 2012 · Viewed 30.3k times · Source

I am using flexslider. There is an example under the advanced tap on this page (in the section "The new, robust Callback API" where they use slider.currentSlide to get the number of the current slide.

How can I access this value in a completely different function? I am thinking of a global variable but I don't know if that will work and I don't know if it's possible to declare a variable within a function as global.

Answer

Lewis picture Lewis · Jun 19, 2013

You can avoid global variables by accessing the flexslider object with:

$(element).data('flexslider')

So in your case you'd use:

$(element).data('flexslider').currentSlide