How to add images (a splitted string in array with .png string concat in each index) in the same div in which script is entered

I am trying to extract everything before the ',' comma. and replace it with a same name image.in a different divs. how can i create a div element dynamically and add all images passed in it and then add this div inside the div with class name slidepop. i want to have different div with classname slidepop and attend div inside it every time. in below code the slidepop div should be open .
here is my codes:

In your script tag I defined a global variable named counter and initialized it with 0.
Now what my written script will do that it will split the passed string same as before. But it will then find all the divs in which class name is slidepop. Now it traverse through each div with $.each() method and when it finds that the index (div no) that is same as counter, it will append the images in that very div. So whenever your splitString() function is called, it will increment the counter (global variable) by 1 so that the function will know that the next images to be placed in next div with class name slidepop