I wanted to make a JavaScript if it repeated in other components of the screen, in this example I'm passing I made a foreach and inside it I put my javascript. the intention is that it repeat itself 10 times, but it only works once. Is there something similar to what I'm trying to do? the intention is for the Ids to be varied at each foreach, but I putting the + i or not it always executes on a single div.
@for (var i = 10; i < 21; i++)
{
<p>A script on this page starts this clock:</p>
<p id="demo+@i"></p>
<script>
var myVar = setInterval(myTimer, 1000);
function myTimer() {
var d = new Date();
document.getElementById("demo"+@i).innerHTML = d.toLocaleTimeString();
}
</script>
}