Click here to Skip to main content
15,879,474 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello,I am new to web programming and asked to show multiple divs dynamically using javaScript
this is the code i am trying but no output is showing:

HTML
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<title>Untitled Document</title>

<style type="text/css">
.inlineDiv{
    display:inline-block;
    float:left;
}

#holder {
    width:100%;
}
</style>

<script type="text/javascript">

var colors = new Array("ff0000","00ff00","0000ff","ff00ff","beeeef");
var n = 5;

for(var i=0;i<n;i++){
    var div = document.createElement('div');
    div.className = "inlineDiv";
    div.style.backgroundColor = "#" + colors[i];
    div.style.width = ($('#holder').width() / n) + "px";
    div.style.height = "500px";
    document.getElementById('holder').appendChild(div);
}

</script>



</head>

<body>

<div id="holder"></div>
</body>
</html>


Kindly help me out the mistake i have done.
Posted
Updated 27-Feb-21 18:58pm
v2

Ok got the problem:
I didn't included the
$(document).ready(function() {});
function.
 
Share this answer
 
Bro can you upload full code after updation
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900