Search code examples
javascripthtmlvar

How I can show a Variable Valor in to a h1 in html and js


I'm new to coding things, and I want to learn a lot, so I found Stackoverflow, to solve my question...

The code I have is:

<h1 class="Result" id="result">0</h1> 

Now, I do a basic JS File:

const number = 0;
var elem = document.getElementById('result');

And, now I don't know what to do, to display it in the h1, if someone can help me I would really appreciate it.


Solution

  • These are some of the ways you can dynamically add the value.

    document.getElementById('result').innerHTML = number;

    document.getElementById('result').innerText = number;

    document.getElementById('result').textContent = number;