Hello I am fairly new to jquery, I have researched this topic on this forum and this still doesn't work for me. I have a gallery that is playing images that I want to add a pause button to. I can't get the code to respond respond to a click on the button.
<input type ="button" id="toggleAutoPlayBtn" value="PAUSE"/>
I have tried this to test (didn't work):
$(document).on('click', '#toggleAutoPlayBtn', function(){
$("p").text("clicked!");
});
I have also tried this to test (didn't work)
$(function(){
$("#toggleAutoPlayBtn").click(function(){
alert('clicked!');
});
});
I have tried exchanging 'id' to 'class' (# to .) (didn't work) I have tried "live" instead of "on" (didn't work)
This is the actual code: it's in my footer and I'm running this out of WP:
<footer id="colophon" role="contentinfo">
<div id="footer"> <input type ="button" id="toggleAutoPlayBtn" value="PAUSE"/> </div>
<script>
$(document).on('click', '#toggleAutoPlayBtn', function(){
$("p").text("clicked!");
});
</script>
</footer><!-- #colophon -->
</div><!-- #page -->
<?php wp_footer(); ?>
</body>
</html>
This is my final code:
$(document).on('click', '#toggleAutoPlayBtn', function(){
var autoStart = true;
$('#new-royalslider-2').royalSlider({
// other options...
autoPlay: {
enabled: autoStart
}
});
$('#toggleAutoPlayBtn').click(function() {
// optionally change button text, style e.t.c.
if(autoStart) {
$(this).html('play');
} else {
$(this).html('pause');
}
autoStart = !autoStart;
$('#new-royalslider-2').royalSlider('toggleAutoPlay');
});
});
Can't remember if I have tried anything else now, maybe I'm missing some basic step? Does it matter where the button is? Of course I do have the code wrapped in . Any other really basic things I might have overlooked?
Many thanks for any response.
.toggleAutoPlayBtninstead of#toggleAutoPlayBtn?