Your $('.two')
click function is running on $(document).ready()
, but no elements exist with that class at that time so the function is not bound to anything. What you need to do is add a click handler to the element at the time you are adding the .two
class at the end of the animation:
$(document).ready(function() {
$( ".one" ).click(function() {
$('.adventurevideoviewmore').addClass('two');
$( ".adventure2" ).slideDown( 1000, function() {
$( ".two" ).click(function() {
$( ".adventure3" ).slideDown( 1000, function() {});
});
});
});
});
This may cause you headaches though since the user can still click the .one
element and have the handler added again. It looks like you are trying to create a wizard of some kind. If so, I suggest taking a slightly different approach.
HTML
Wrap the adventure is some kind of container if it isn't already
<div class="adventure-wizard" data-step="1" data-last="3">
<div class="adventure1"></div>
<div class="adventure2"></div>
<div class="adventure3"></div>
<div class="adventurevideoviewmore"><img src="images/homepage/viewmorebutton.png"/></div>
</div>
JavaScript
Maintain the state in data on the container instead of classes on elements. This allows your view more button to always use the same handler and increment the wizard along.
$(document).ready(function() {
// Setup the click event on the view more button to increment the step and
// animate the appropriate adventure element until the last is reached
$('.adventureviewmore').click(function () {
var wizard = $(this).parent();
var step = wizard.data('step');
var last = wizard.data('last');
// If the end is reached do nothing
if (step === last)
return;
// Increment the step
step++;
// Animate the adventure for the next step
$('.adventure' + step).slideDown(1000);
// Store the step back on the wizard
wizard.data('step', step);
});
});
});