delay printing characters in string to console js setTimeout code example
Example 1: how to set timeout for a div tag in html
<script>
const timeout = document.getElementsByClassName('classname')
setTimeout(hideElement, 1000)
function hideElement() {
timeout.style.display = 'none'
</script>
<div class="classname">
<span> × </span>
Example 2: javascript this in settimeout
function func() {
this.var = 5;
this.changeVar = function() {
setTimeout(() => {
this.var = 10;
}, 1000);
}
}
var a = new func();
a.changeVar();