Skip to content
Advertisement

How to access elements of one html in another html file using their id

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.

Advertisement

Answer

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;
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement