Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript

eslam said
PLUS
eslam said
Courses Plus Student 6,734 Points

js 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
MOD
Jonathan Grieve
Treehouse Moderator 90,719 Points

Hi 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
eslam said
Courses Plus Student 6,734 Points

Hello 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 )

    <body
        <!-- script tags -->
        <script src="assets/js/app.js"></script>
    </body>

i even took a copy from index.html and changed its name to another name still the js didn't work

Jonathan Grieve
Jonathan Grieve
Treehouse Moderator 90,719 Points

It'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! :-)

eslam said
PLUS
eslam said
Courses Plus Student 6,734 Points

i 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
PLUS
eslam said
Courses Plus Student 6,734 Points

well 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