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!
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

eslam said
Courses Plus Student 6,734 Pointsjs file not working for all pages
my js file is not working for all pages, it's working fine for the index.html page but not any other new pages i create, despite that all pages have the same source path like so ;
<script src="assets/js/app.js"></script>
3 Answers

Jonathan Grieve
Treehouse Moderator 91,248 PointsHi Eslam,
Are you saving each of your new pages in the same directory as the HTML file?
Can you post an example of your code so we can have a look and see what else might be the issue?
Thanks :)

eslam said
Courses Plus Student 6,734 Pointsi guess the problem might be that the other pages still have access to some elements from index.html, when i checked my console its giving me an error, so is there in anyway to stop other pages to have access to other pages elements ?

eslam said
Courses Plus Student 6,734 Pointswell i will try to make my question more simpler, how to run a block of js code for specified page, instead of making couple of js files of each page
eslam said
Courses Plus Student 6,734 Pointseslam said
Courses Plus Student 6,734 PointsHello there jonathan, yes indeed they are both in the same directory, the index.html is really long so i will share with you the end of the body
body ( identical for both pages )
i even took a copy from index.html and changed its name to another name still the js didn't work
Jonathan Grieve
Treehouse Moderator 91,248 PointsJonathan Grieve
Treehouse Moderator 91,248 PointsIt's probably something really simple causing the script not to work for the other pages. If you're sure the directory structure is sound, try searching each of your script tags for incomplete tags and that you haven't made a mistake in the source attributes! :-)