+ 3

How to write this shorter?

I don't knew, hot to write this shorter I mean all this div's. This at once: <div id="interactive"> </div> <div style="margin-left: 50px" id="interactive"> </div> <div style="margin-left: 100px" id="interactive"> </div> <div style="margin-left: 150px" id="interactive"> </div> <div style="margin-left: 200px" id="interactive"> </div> <div style="margin-left: 250px" id="interactive"> </div> <div style="margin-left: 300px" id="interactive"> </div> <div style="margin-left: 350px" id="interactive"> </div> <div style="margin-left: 400px" id="interactive"> </div> <div style="margin-left: 450px" id="interactive"> </div> <div style="margin-left: 500px" id="interactive"> </div> <div style="margin-left: 550px" id="interactive"> </div> <div style="margin-left: 600px" id="interactive"> </div> <div style="margin-left: 650px" id="interactive"> </div> <div style="margin-left: 700px" id="interactive"> </div> <div style="margin-left: 750px" id="interactive"> </div> <div style="margin-left: 800px" id="interactive"> </div> <div style="margin-left: 850px" id="interactive"> </div> <div style="margin-left: 900px" id="interactive"> </div> <div style="margin-left: 950px" id="interactive"> </div> <div style="margin-left: 1000px" id="interactive"> </div> <div style="margin-left: 1050px" id="interactive"> </div> <div style="margin-left: 1100px" id="interactive"> </div> <div style="margin-left: 1150px" id="interactive"> </div> <div style="margin-left: 1200px" id="interactive"> </div> ... Code: https://code.sololearn.com/WO5kU8e1v2Vw/#html

10th Mar 2019, 9:53 PM
Konrad Korpik
Konrad Korpik - avatar
5 Antworten
+ 3
Replace all div-s with this script <script> for(i= 0; i< 1851; i+=50){ document.write("<div style='margin-left: "+i+"px' id='interactive'></div>"); }</script>
10th Mar 2019, 11:10 PM
Vilson Bujaj
Vilson Bujaj - avatar
+ 6
Hey, You can create the elements in javascript inside a for loop and append them to the document.
10th Mar 2019, 11:16 PM
D_Stark
D_Stark - avatar
+ 2
I can't help u... But This looks Nice. Good inspiration... Thanks
11th Mar 2019, 10:09 AM
Rasmus Andersen
0
Remember you should have unique id in each div.
12th Apr 2019, 10:33 PM
sEver
21st Jul 2020, 3:17 AM
shubham kumar
shubham kumar - avatar