OneCompiler

CSS Grid Use JavaScript



<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Apna collage html task</title> </head> <body> <style> body { display: flex; height: 800px; }
    .part1 {
        width: 18%;
        height: 100%;
        margin: 5px 5px;
    }
    
    .div1 {
        width: 100%;
        height: 400px;
        background-color: greenyellow;
        margin: 5px 5px;
    }
    
    .div2 {
        height: 266px;
    }
    
    .div3 {
        height: 160px;
    }
    
    .div4 {
        height: 114px;
    }
    
    .div5 {
        height: 88px;
    }
</style>


<div class="part1" id="div1">
</div>
<div class="part1" id="div2">
</div>
<div class="part1" id="div3">
</div>
<div class="part1" id="div4">
</div>
<div class="part1" id="div5">
</div>


<script>
    function callRow(div, number, divRow) {
        for (let a = 0; a <= number; a++) {
            let createDiv = document.getElementById(div);
            let createAttribute = document.createElement("div");
            createAttribute.setAttribute('class', `div1 ${divRow}`);
            createAttribute.textContent = 'part-' + a;
            createDiv.append(createAttribute);
            console.log(number)
        }

    }
    callRow('div1', 1);
    callRow('div2', 2, 'div2');
    callRow('div3', 4, 'div3')
    callRow('div4', 6, 'div4')
    callRow('div5', 8, 'div5')
</script>
</body> </html>