in

How to use one JavaScript file for two HTML files?


I want to extract the html from list1.html and use it in list2.html, using JavaScript or jQuery.

list1.html

<ul>
    <li class="listitem" id="data1">DATA 1</li>
    <li class="listitem" id="data2">DATA 2</li>
    <li class="listitem" id="data3">DATA 3</li>
</ul>

list2.html

<ul>
    <li class="getitem" id='getitem1'></li>
    <li class="getitem" id='getitem2'></li>
    <li class="getitem" id='getitem3'></li>
</ul>

Is there any way to show the texts DATA1, DATA2, DATA3, respectively, in #getitem1 , #getitem2, and #getitem3?

Here’s what I have so far (Not working)

script.js

data1 = document.getElementById('data1').innerText();
data2 = document.getElementById('data2').innerText();
data3 = document.getElementById('data3').innerText();

document.getElementById('getitem1').innerText(data1);
document.getElementById('getitem2').innerText(data2);
document.getElementById('getitem3').innerText(data3);



Source: https://stackoverflow.com/questions/70553844/how-to-use-one-javascript-file-for-two-html-files

A Bayesian Course Using CmdStanPy and Plotnine

How To Use Preg_Match In php To Get Multiple Values From Json Data