Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

multiple javascript code in one file

How do I set up a Javascript file with multiple bits of code? When ever I add existing code to my file it cancels out the first bit.

I know it's probably something really simple.

var main = function() {

/* Push the body and the nav down by 130px */ $('.menu-icon').click(function() { $('.nav_links').animate({ top: "0px" }

, 400);

$('body').animate({
  top: "700px"
}, 400);

});

/* Then push them back */ $(a).click(function() { $('.menu').animate({ top: "-700px" }, 400);

$('body').animate({
  top: "0px"
}, 400);

});

};

$(document).ready(main);

$(document).ready(function() { // Scroll the whole document $('body').localScroll({ target:'body' });

        }); 

        $(document).ready(function() {

            $('.nav_links li a').click(function(e) {

                $('.nav_links li a').removeClass('active');

                var $parent = $(this);

                if (!$parent.hasClass('active')) {

                    $parent.addClass('active');

                }

                e.preventDefault();
            });

        });

        $(document).ready(main);

1 Answer

It's called concatenation. We use gulp for that.

gulp

It's very good course. Go do it. :)