Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery - get all src of images in div and put into field

I want to modified this tutorial to my requirements but there is one problem to me. I'm a beginner with jQuery and I would like to get all image sources from specifïc div and put them into field. There is a variable images which is field and contain some images but I want instead of this get all image sources from div and put them into field images. I know that isn't such a complicated but I don't really know how to do it.

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

This is the variable image from source on jsfiddle which I want fill from div instead what I have there 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 advance.

like image 272
Jaroslav Klimčík Avatar asked Aug 07 '13 11:08

Jaroslav Klimčík


3 Answers

In dom ready try

var images = $('.thumbnailArrows').children('img').map(function(){
    return $(this).attr('src')
}).get()
like image 124
Arun P Johny Avatar answered Nov 12 '22 14:11

Arun P Johny


Assuming by "field" you mean variable or Array:

var images = $('#imageHolder').find('img').map(function() { return this.src; }).get();
like image 25
André Dion Avatar answered Nov 12 '22 13:11

André Dion


You can just 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

like image 1
knikolov Avatar answered Nov 12 '22 13:11

knikolov