Jump to content

Document.getelementbyid on different HTML


tonynsx

Recommended Posts

I’m a new user and new to JS, so please bear with me.

I have 3 files in the same folder, main.html, test.html and script.js

In my main.html, I have

script src="script.js", and <p id = "test"></p>
In my test.html, I have

script src="script.js", and <p id = "tt"></p>
In my script.js, I have a function:

 function test() {
 	document.getElementbyId("test").innerHTML = "this is in main.html"
 	document.getElementbyId("tt").innerHTML = "this is in test.html"
 {

But, when I call the function with a button, only the main.html 

with id “test” is updated with “this is in main.html”, how come the 

with id “tt” in test.html is not updated with “this is in test.html”?

 

Link to comment
Share on other sites

The first in main page exists, shows, second does not exist = undefined error STOP!

The first in test page does not exist = undefined error STOP! never gets to second to show.

Either check with if condition, if specific id reference exists within page before going any further.

Edited by dsonesuk
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...