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
Chuck Robertson
3,408 PointsJavaScript Equivalent of PHP include
I would like to know if anyone knows the equivalent way to call on pieces of HTML code from another file like you can with PHP include:
For example: php include 'navbar.php';
I'm aware you can reference the file in the code...
<script src="js/navbar.js"></script>
But how do I write the function that gets called to include all the HTML and CSS for my navbar and then call on that from any HTML page?
1 Answer
Jonathan Grieve
Treehouse Moderator 91,254 PointsHi Chuck,
You migh try looking at this link for some help with this, I migh be wrong but I don't think JS has an include of its own.
http://stackoverflow.com/questions/22271851/javascript-equivalent-of-phps-include
It links to something called require JS but also talks about script tags which of course link to external JS files on your server or drive, :-)