I have been working on a project which requires a 3-d carousel, so i decided to take the help of Materialize CSS, but i'm facing an issue of adding any image to it using javascript. I wanted to append an image under the div of class "carousel-item" which is under div of class "carousel" to the following code,
<div class="carousel" id="grandparent">
<div class="carousel-item"><img src="image1.jpg" name="image-1"></div>
<div class="carousel-item"><img src="image2.png" name="image-2"></div>
<div class="carousel-item"><img src="image3.jpg" name="image-3"></div>
<div class="carousel-item"><img src="image4.jpg" name="image-4"></div>
<div class="carousel-item"><img src="image5.jpeg" name="image-5"></div>
<div class="carousel-item"><img src="image6.jpg" name="image-6"></div>
</div>
This is what i tried,
var divmain=document.getElementById("grandparent");
var newdiv=document.createElement("div");
newdiv.className+="carousel-item";
divmain.appendChild(newdiv);
var image=document.createElement("img");
image.setAttribute("src","image7.jpeg");
image.setAttribute("name","image7");
newdiv.appendChild(image);
But the above code is just overlapping the image on the top of carousel and even not moving with the carousel slide.
Can anybody help?