I know maybe is not the right way of using the getElementsByClassName
. For example the code below doesn't work as it is ¿why?, but when change getElementsByClassName("demo")
for getElementById("demo2")
does work
<!DOCTYPE html>
<html>
<body>
<p>Click the button.</p>
<button onclick="myFunction()">Try it</button>
<p class="demo" id="demo2">anything</p>
<script>
function myFunction() {
var str = "How are you doing today?";
var res = str.split(" ");
document.getElementsByNameClass("demo").innerHTML = res;
}
</script>
</body>
</html>