Click here to Skip to main content
15,893,594 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi everyone! I have a problem in my code in JavaScript.. And I dont why but happened

Quote:
This is the error:
Uncaught TypeError: container is null


And this is my code:
let html='';
for (let i = 0; i < 88; i++) {
 html+= `<span>${i}</span>`;
for(let j=0; j< 52; j++){
 html+= '<input type="checkbox">';
}
html+= '<hr>';
}

const container=document.getElementById("container");
container.innerHTML=html; HERE IS THE PROBLEM


What I have tried:

Hi tried very thing but nothing
Posted
Updated 18-Oct-22 4:55am

Simple: there is no element with an ID of "container" so getElementById returns null, just as it is intended to and as described in the documentation: Document.getElementById() - Web APIs | MDN[^]
Why not? That is the question, and not one we can answer - we have no access to your page or it's HTML.

So start by looking at what you think your page contains, and if you don't find the problem there use your browser debug facilities ("Inspect" and "View Source" are a good starting point) to look at where you think container should be.

Sorry, but we can't do any of that for you!
 
Share this answer
 
1 you need to add div with container id

2 simply add whole code into your useEffect hook and watch.
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900