Issue
I'm new to Javascript and I've tried to print multiple Strings but only the last statement is executed, Code:
<html>
<body>
<p id = "demo"></p>
<script>
document.getElementById("demo").innerHTML = "Toit"
document.getElementById("demo").innerHTML = "Noice";
document.getElementById("demo").innerHTML = "Epic";
</script>
</body>
Output:
Epic
Solution
Every statement override the previos one.
You should do:
<html>
<body>
<p id = "demo"></p>
<script>
document.getElementById("demo").innerHTML = "Toit"
document.getElementById("demo").innerHTML += "Noice";
document.getElementById("demo").innerHTML += "Epic";
</script>
</body>
By using +=
you concat the last value, which is exactly the same like doing:
document.getElementById("demo").innerHTML =
document.getElementById("demo").innerHTML + "Epic";
Answered By - guyaloni Answer Checked By - David Marino (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.