So, for a school project I need to make a website. I am very new to programming but I have had experiences in the past. I was making a tab function that displayed a paragraph with information. For personal reasons I blocked out the info with a -, but this is the part I am having problems with.
Html:
<h1 class="text-center">CSS</h1
<div id="css">
<h2 class="text-center">-</h2>
<p class="text-center">-</p>
</div>
<hr>
Javascript:
//Css toggle
document.getElementById("css").onclick = function() {
if (css1 == 0) {
document.getElementById("css").style.display = "block";
css1 = 1
} else {
document.getElementById("css").style.display = "none";
css1 = 0
} }
The part I am having problems with is in the javascript.
document.getElementById("css").onclick = function() {
In the console it gives an error that says "Uncaught TypeError: Cannot set properties of null (setting 'onclick')"
My question is. What is going wrong?