I tried looking at other threads with similar issues, but still can't seem to get this resolved.
Currently, I have a search bar that displays relevant results after the user hits a button. This works.
The user is then able to click on any one of the results and have it take them to a new HTML page. This also works.
I am trying to display a variable from the JS file on the HTML page, and I've tried using .innerHTML, but I keep getting the error:
onePage.js:61 Uncaught TypeError: Cannot set property 'innerHTML' of null
This is what I have in my HTML file:
<div id="output"></div>
And this is what I have in my JS file:
function setList(group) {
clearList();
for (const state of group) {
const item = document.createElement('li');
item.classList.add('list-group-item');
const text = document.createTextNode(state.name);
var newListItem = document.createElement("li");
var newAnchor = document.createElement("a");
newAnchor.textContent = state.name;
document.getElementById("output").innerHTML = text; // line where I get error
newAnchor.setAttribute('href', "displayInfo.html");
newListItem.appendChild(newAnchor);
list.appendChild(newListItem);
console.log(newListItem);
}
Can someone please help me out? Thanks in advance!