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 jQuery Basics (2014) Creating a Mobile Drop Down Menu Perform: Part 1

Christopher Wallace
Christopher Wallace
6,277 Points

Quick Question,

When your creating Jquery code do you typically put all the code into one page or multiple pages

Michael Liendo
Michael Liendo
15,326 Points

When you say "page" do you mean webpage, or JavaScript file?

1 Answer

Michael Liendo
Michael Liendo
15,326 Points

In JavaScript, creating modular files is a best practice. Meaning, keeping small reusable parts together makes the most sense. Since jQuery is just a library that sits on top of javascript, the same is true. In one file, I might have jQuery that makes a call to the server and returns the contents. In another, I might have jQuery that adds elements to the DOM. It just depends on my need. To put shortly, you should never have a all your code in one .js file, though seemingly fine for smaller projects, it can turn into a nightmare to maintain as your projects become more complex.