I have created 2 functions in javascript, these functions are fired on click events, the problem is that after the for loops, alerts are not executed.
function myfunc() {
for (var i = 0; i < 4; i++) {
document.getElementsByTagName("h1")[i].style.color="red";
}
alert("alert 1"); //this should be executed after the for since it is part of the function code.
}
function myfunc2() {
for (var j = 0; j < 4; j++) {
document.getElementsByTagName("h1")[j].style.color="navy";
}
alert("alert 2"); //this should be executed after the for since it is part of the function code
}
<h1 onClick="myfunc()">primo h1</h1>
<h1 onClick="myfunc2();">secondo h1</h1>
onclick(without a capital letter), I don't know if the case is important.<h1>s for each function?var h1Len = document.getElementsByTagName("h1").length;and use insted of the hardcoded number