How to replace innerHTML of a div using jQuery? Copy. var img = document.createElement("img"); The above example demonstrates all the three cases, looping over specific child elements, looping over child elements with a specific id, and looping over child elements with a specific class. Example: Assuming I have an array of images. Therefore, we can access the … First, declare a variable counter and initialize it to 1.; Second, display the value of counter in the Console window if counter is less than 5.; Third, increase the value of counter by one in each iteration of the loop. How to get the height of a div using jQuery ? edit With that, add height:100px and set margin. Using for loop and createElement() to Print out Array Content in Javascript . To loop through the child elements, the jQuery each() method is used as demonstrated in the following example. How to play video on hover on a div using jQuery ? How to iterate through child elements of a div using jQuery ? How to Align modal content box to center of any screen? How to set the default value for an HTML