Search code examples
jqueryclickcycle

Any reason why this .click is not working


I have this page that i have a rotate slideshow running. I have it currently changing every second for testing. The slideshow works great but stopping it it not easy for some reason. I have a link on the top that should stop it.

<a class="stop" href="#">Stop to play the video</a>

$('.stop').click(function(){
   $('#slideshow').cycle('stop');
});

This should stop the script but doesnt. But if you open up firebug and paste this line into the console the script stops. What gives?

   $('#slideshow').cycle('stop');

Solution

  • Just had a closer look at your code and you're emitting the javascript outside of your $(document).ready(...) handlers and before the element in the html, so you're trying to attach the event to an element that doesn't exist.

    Either move your click handler inside a the $(document).ready(...) or put it below the link in the html.