-2

I have written some custom function for image slider but it not get called

following is my code.

carousel: {
  init: function() {
      // main function to run
  }
  previous: function() {
     // function to run when they want to go back
  },
  next: function() {
    // function to run when they want to go forward
  }
}

and i am calling it like onclick=javascript:previous() but I get the following error on console :

previous() not defined
akmozo
  • 9,829
  • 3
  • 28
  • 44
Ganesh Gudghe
  • 1,327
  • 1
  • 17
  • 41

1 Answers1

1

If carousel is the top level of that object.

You need to call the function previous by referring to it as the property of the object:

onclick=carousel.previous()
Sinan Guclu
  • 1,075
  • 6
  • 16
  • Actually they have `carousel: {` which makes it look like `carousel` is a property of some other object, so they need to access whatever the top most object is and access each property down to `previous` – Patrick Evans Jul 12 '16 at 11:30