Check out this example for demonstrating show/hide functionality:
http://jsfiddle.net/rVwkn/14/
Using jQuery:
$('#stepbtn').click( function() {
if ($('#step2').is(':visible')) {
$('#step3').show();
$('#stepbtn').hide();
} else if ($('#step1').is(':visible')) {
$('#step2').show();
}
});
$('#backbtn').click( function() {
if ($('#step3').is(':visible')) {
$('#step3').hide();
$('#stepbtn').show();
} else if ($('#step1').is(':visible')) {
$('#step1').hide();
}
});
CSS Styles:
#step2 {
display:none;
}
#step3 {
display:none;
}
#backbtn {
display: none;
}
HTML Markup:
<div id="step1">
<h3>Step 1</h3>
</div>
<div id="step2">
<h3>Step 2</h3>
</div>
<div id="step3">
<h3>Step 3</h3>
</div>
<button id="stepbtn">Next Step</button>
<button id="backbtn">Go Back a Step</button>
Updated Version:
For added flexibility, here is another version of the example:
http://jsfiddle.net/ddr6D/6/
Using jQuery:
$(document).ready( function() {
var current_step = 1;
var max_number_of_steps = 6;
$('#stepbtn').click( function() {
var next_step = current_step + 1;
$('#step'+next_step).slideDown();
$('#backbtn').show();
current_step++; // increase the step we are on...
if (current_step == max_number_of_steps) {
$('#stepbtn').hide();
}
});
$('#backbtn').click( function() {
$('#step'+current_step).slideUp();// hide it first,
current_step--; // update the correct step
if (current_step == 1) {
$('#backbtn').hide();
}
if (current_step < max_number_of_steps) {
$('#stepbtn').show(); // show when hidden...
}
});
});
CSS Styles:
#step2,#step3,#step4,#step5,#step6 {
display:none;
}
#backbtn {
display: none;
}
HTML Markup:
<div id="step1">
<h3>Step 1</h3>
</div>
<div id="step2">
<h3>Step 2</h3>
</div>
<div id="step3">
<h3>Step 3</h3>
</div>
<div id="step4">
<h3>Step 4</h3>
</div>
<div id="step5">
<h3>Step 5</h3>
</div>
<div id="step6">
<h3>Step 6</h3>
</div>
<button id="stepbtn">Next Step</button>
<button id="backbtn">Go Back a Step</button>