KOMPX.COM or COMPMISCELLANEA.COM   

How to call a function multiple times (JavaScript)

Calling a function multiple times in JavaScript. Using for loop:

HTML code:


<div class="example"></div>

JavaScript code:


<script>
function multiple_times() {
	document.querySelector('.example').innerHTML += 'Calling the function' + '<br />';
}

for ( var i = 0; i < 3; i++ ) {
	multiple_times();
}
</script>

Browser support
Windows
Edge 12.0+
Firefox 3.5+
Google Chrome 1.0+
Opera 10.0+
Linux
Firefox 3.5+
Google Chrome 1.0+
Opera 10.0+
iOS
Safari 2.0+
Android
Samsung Internet 1.0+
Chrome Android 18.0+
Firefox for Android 4.0+
Opera Android 10.1+
More