Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
23 lines (22 sloc) 524 Bytes
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Good for loop</title>
</head>
<body>
<script>
for(let i = 1; i <= 10; i++) {
const para = document.createElement('p');
para.textContent = 'This is paragraph ' + i + '.';
document.body.appendChild(para);
addHandler(para, i);
}
function addHandler(para, i) {
para.onclick = function() {
alert('Hello from paragraph ' + i + '!');
}
}
</script>
</body>
</html>
You can’t perform that action at this time.