Ask coding questions

← Back to all posts
4
Why is my javascript not working on all of my pages?

I´ve tried to connect my JS(script.js) to other files on my project, only works with index.html. here is my project https://repl.it/@Jose_CC/Photo-page-project . Please help, I love relp! I dont want to stop using it because of a small problem like this

Commentshotnewtop
1

You know there's such a thing as screenshots, right?

1

Just want to check: I see that you are testing within the workspace page, which really only shows index.html and will never load any other html file - therefore, any div elements you have existing in other files will never be loaded onto the page. If you open it in a new tab and test it there, navigating to different files, does it work there as expected?

1

@timmy_i_chen No, only works if I´m in the current page. For example, if I´m in index.html and I try to select something from about.html the result will be nun, but if I´m in the about page it´ll select the ID.

1

@Jose_CC Can you share with us a repl that reproduces this issue on a small scale? There's a lot going on in the photo page project.

1

@Jose_CC I mean, can you reproduce this minimally in a new repl?

1

@timmy_i_chen sure, give me a few minutes. thank you for your time

1

so sorry for the waiting, I had some issues with my phone camera.
https://repl.it/@Jose_CC/AshamedNoxiousAddons
@timmy_i_chen




1

@timmy_i_chen is that ok? I still have the same problem

1

@Jose_CC Yes, I can see now - thanks for reproducing. This is working as expected:

The thing is, whenever you re-run the repl, it will always go back to index.html, which is why it can't find #two-try. If you try by popping out the browser it should be a lot more clear.

1

@timmy_i_chen Mannnnn! thank you so much!!!!! I´m so happy right now!

1

Here are more examples of my problem, thank you in advance





1

Make sure your JQuery is included on every page.

Please upvote this comment if it helped you in any way.

1

@Vandesm14 Than you for replying, I created a new ID and added a link to jQuery to the about page, I´ve tried to select the ID using plain js and jquery and nothing.

1

Are you sure it works with only index.html?