Calling a JS function in HTML twice [closed]

1 day ago 1
ARTICLE AD BOX

You cannot use two <body> tags in a single HTML document.
Instead, call the function multiple times inside the same onload.

<html> <body onload="test(); test();"> <div id="score">0</div> <script> function test() { const scoreDiv = document.getElementById('score'); let score = parseInt(scoreDiv.innerText); score += 1; scoreDiv.innerText = score.toString(); } </script> </body> </html>

This will call test() twice when the page loads, so the final score will become 2.

Mahesh Shinde's user avatar

Read Entire Article