treehouse : what would you like to learn today?
Web Design Web Development iOS Development

[Solved] javascript help

  • I am working on a site to get a div to slidetoggle up and down. It seems to be doing it. When I push the link, the div goes down and when I push it again, it goes up. Problem is that when I do push the link which is just an empty link with a class, the page jumps to the top. I need to prevent the default action of the link. I thought I could do it with e.prevendDefault() but that seems to disable the link all together and the div stops working. Do you know how to do this?


    <script>
    $(document).ready(function(){
    $(".controls").click(function(){
    $("#logo-background").slideToggle("slow");
    });
    });
    </script>



    <div id="arrows"> <!--holds the background images for the controls-->
    <a class="controls" href="#"></a>
    </div><!--END arrows-->
    <div id="logo-background"><!--This is the div that will slide toggle-->
    <div id="logos">

    </div><!--END logos-->
    </div><!--END logo-background-->

  • Should work fine. Here's a quick demo: http://codepen.io/ggilmore/pen/BGxKm

    Just have to make sure to put function(e) before using e.preventDefault().

    Also, not sure if this was the problem, but you misspelled 'prevent' in your post.
  • thanks Doc, I missed the e in the function(e). That is why it didn't work. It's working now.