+ 1

This can be modified or not( I mean it can be shorten or not)

<div class="number">100%</div> //script tag here let counter = 0; onload = () => { const numb = document.querySelector(".number"); setInterval(() => { if(counter === 100) clearInterval(); else numb.innerHTML = ++counter + "%"; }, 100); } //end of script tag

18th Jul 2022, 3:29 PM
Saddam Hussain
Saddam Hussain - avatar
2 Respuestas
+ 2
Just write in single line
18th Jul 2022, 3:49 PM
A͢J
A͢J - avatar
0
When you use js after your elements you dont need to use onload event, so if you remove it you will save few lines, and also place everyting you can in one line as AJ said. Onload allow script to load at end. But if every selected element are above script, you dont need onload. But on sololearn if you type your javascript inside js tab, it is same as script at head and will show you error, so you need to use it. Here is code where I explained how it works, you can also see order of scripts by console log message. https://code.sololearn.com/WPHmkG0Q5hCD/?ref=app
18th Jul 2022, 4:47 PM
PanicS
PanicS - avatar