How to set multiple images in a loop javascript?

     In the following javascript code is used to create the html img tag dynamically and append it to the specified div in a loop.

Create Image tag using javacript
     Usually we are directly create the html tag in the html code, but if you want to create this img tag dynamically you can follow the below code.


   var img = document.createElement("img");

   img.src = "http://www.google.com/intl/en_com/images/logo_plain.png";



   var src = document.getElementById("elementid");

   src.appendChild(img);


Set multiple images in a loop
     If you want to add only one image, you can follow the above method. If you want to append more images dynamically you can follow the below method.



Example Program:- (Editor)


Editor is Loading...

Advertisement

0 nhận xét:

Đăng nhận xét