JQuery - get all src images in a div and put in a field

I want to change this tutorial according to my requirements, but there is one problem for me. I start with jQuery and I would like to get all the image sources from the specïc div and put them in the box. There is a variable image that is a field and contains some images, but instead I want to get all image sources from a div and put them in field images. I know that this is not so difficult, but I do not know how to do it.

The source is here http://jsfiddle.net/s5V3V/36/

This is a variable image from a source on jsfiddle that I want to fill out from a div instead of what I have now:

images = ['http://kimjoyfox.com/blog/wp-content/uploads/drwho8.jpg', 'http://kimjoyfox.com/blog/wp-content/uploads/drwho7.jpg', 'http://kimjoyfox.com/blog/wp-content/uploads/drwho6.jpg', 'http://kimjoyfox.com/blog/wp-content/uploads/drwho5.jpg', 'http://kimjoyfox.com/blog/wp-content/uploads/drwho4.jpg', 'http://kimjoyfox.com/blog/wp-content/uploads/drwho3.jpg', 'http://kimjoyfox.com/blog/wp-content/uploads/dr-whos-tardis.png', 'http://kimjoyfox.com/blog/wp-content/uploads/drwho9.jpg', 'http://kimjoyfox.com/blog/wp-content/uploads/drwho1.jpg']; 

Thanks in advance.

+4
source share
5 answers

In a home attempt

 var images = $('.thumbnailArrows').children('img').map(function(){ return $(this).attr('src') }).get() 
+10
source

Assuming "field" means a variable or an array:

 var images = $('#imageHolder').find('img').map(function() { return this.src; }).get(); 
+6
source

You can simply loop with .each () and get the attribute

 (function(){ var images = []; $("#imageHolder img").each(function(){ images.push($(this).attr('src')) }) console.log(images); })() 

http://jsbin.com/ogekos/1/edit

+1
source

If you say you want to create an images variable that will be an array filled with src urls from all the img elements in your thumbnails div, you can do this:

 var images = $("#thumbnails").find("img").map(function() { return this.src; }).get(); 

(If I chose the wrong div as the container, you can fix this by replacing "#thumbnails" with a selector for any valid div, possibly "#imageHolder" .)

Please note that the use of the term "field" is incorrect. You seem to mean an array or maybe just a variable.

0
source

find a fix for your problem:

  var images = $(".thumbnailArrows").find('img').map(function () { return $(this).attr('src') }).get() 
0
source

Source: https://habr.com/ru/post/1495719/


All Articles