I have a page with interactive divs that switch content when clicked. When the div button (closing content) is pressed a second time, the page jumps up.
I see that this is the problem of other people, but all the solutions that I found are related to the anchor tag, which is not a problem here.
I tried changing my code to a solution here and added return false; and event.preventDefault(); but none of them worked. What am I doing wrong?
jQuery:
$(document).ready(function(){ $('h1').animate({"right":"147px"},3000); $('.more').toggle( function(){ $(this).css({ 'z-index':'100', 'background-position': '41px 0px' }); $('#heroFullColor').hide(); $('#heroNoColor').show(); $('div.' + $(this).attr('id')).fadeIn('fast'); $('.more').not(this).hide(); }, function(){ $(this).css({ 'background-position': '0px 0px' }); $('div.' + $(this).attr('id')).fadeOut('fast'); $('#heroNoColor, .infoWindow').hide(); $('#heroFullColor').fadeIn('fast'); $('.more').not(this).show(); }); });
HTML structure (this repeats several times on the page):
<div class="more" id="franceFlag"></div> <div class="infoWindow franceFlag"> <img class="imageOn" src="images/lp_foundry_on-franceFlag.jpg" width="71" height="213" alt="French Flag" id="franceFlagOn" /> <p class="franceFlag">blah blah blah</p> </div> <div class="more" id="heliBoth"></div> <div class="infoWindow heliBoth"> <img class="imageOn" src="images/lp_foundry_on-heliBoth.jpg" width="296" height="750" alt="Helicopters" id="heliBothOn" /> <p class="heliBoth">blah blah blah</p> </div>
Here is the fiddle - if you scroll right to the right and click the + sign next to the flag, you'll see what I mean.
source share