It seems that the other answers are not quite what the OP is looking for. From what I understand, OP wants:
- Hide
#content-reveal
on page load - Fade-in
#content-reveal
on button click - No need to switch
#content-reveal
(i.e. after displaying, it should remain displayed)
Based on this, here is my solution:
$(document).ready( function() { $('#content-reveal').hide(); $('#show-button').click( function() { $('#content-reveal').fadeIn( 500 ); } ); } );
jsfiddle here: http://jsfiddle.net/xK83w/
EDIT: based on the changes to the OP question, here is an approach that will do what you want to accomplish:
$(document).ready( function() { $('#content-reveal').hide(); $('#info').click( function() { $('#content-reveal').fadeOut( 500, function() { $('#content-reveal').html( '<b>info HTML</b>' ); $('#content-reveal').fadeIn( 500 ); } ); } ); $('#search').click( function() { $('#content-reveal').fadeOut( 500, function() { $('#content-reveal').html( '<b>search HTML</b>' ); $('#content-reveal').fadeIn( 500 ); } ); } );
Updated jsfiddle here: http://jsfiddle.net/xK83w/1/
However, if your content blocks contain a lot of HTML, you might want to consider a different approach so that you don't burden your Javascript with a lot of HTML text. For example, you can have four different div
s and choose between them like this:
<div id="content"> <div id="content-reveal-info"> <ul id="newsticker_1" class="newsticker"> <li>Lorem ipsum dolor sit amet, consectetur adipisicing elit...</li> <li>Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip...</li> <li>Duis aute irure dolor in reprehenderit in voluptate velit esse cillum...</li> <li>Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia...</li> <li>Bubble bubble ipsum dolor sit amet, consectetur adipisicing elit...</li> </ul> </div> <div id="content-reveal-search"> <b>search HTML</b> </div> <div id="content-reveal-player"> <b>player HTML</b> </div> <div id="content-reveal-socials"> <b>socials HTML</b> </div>
Then create a function to actually switch:
var activeElement; function activateElement( eltSuffix ) { if( activeElement ) { activeElement.fadeOut( 500, function() { activeElement = $('#content-reveal-'+eltSuffix); activeElement.fadeIn( 500 ); } ); } else { activeElement = $('#content-reveal-'+eltSuffix); activeElement.fadeIn( 500 ); } }
Then finally hook up the event handlers:
$(document).ready( function() { $('#content div').hide(); $('#info').click( function() { activateElement('info'); } ); $('#search').click( function() { activateElement('search'); } ); $('#player').click( function() { activateElement('player'); } ); $('#socials').click( function() { activateElement('socials'); } ); } );
jsfiddle here: http://jsfiddle.net/xK83w/1/