Home > front end >  How to access elements of one html in another html file using their id
How to access elements of one html in another html file using their id

Time:11-20

I have created two html files ( file1.html and file2.html ).

In file2, I have 10 paragraphs each having a unique id . How can I access these paragraphs using their id in file1.

CodePudding user response:

This can be solved with Javascript using the .getElementById method. This can be accomplished via localStorage. Below are steps to save data from file2 to the point where you're actually able to use it in file1

you can use localStorage 
for example in file2.html you save data with
var thing = document.getElementById('id').value;
localStorage.something = thing ; 
then in your file1.html you can use it by
document.getElementById("id").innerHTML=localStorage.something;
  •  Tags:  
  • html
  • Related