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

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 91,252 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 91,252 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