holyredbeard
holyredbeard

Reputation: 21198

Getting values from different input fields with same class name

I'm working on an image sharing site, and right now I'm working on rendering out a users albums on a page. Each of the albums contains of at least on image, and I want to show all the albums as boxes with four thumbnails (the first four images in the album) in each of the boxes.

The images file names is stored in the value of a hidden input field in each of the boxes, and what I want to do is to get all the file names from each of the album boxes and show them as thumbnails.

The part that I need help with is how I shall get the file names from each of the album boxes, one by one. The code below doesn't work by obvious reasons, but how can it be rewritten so it works? All the input fields has the same class name.

Thanks in advance!

    if ($('.hiddenAlbumNames').length > 0){

        var images = $(this).val();

                    // the rest of the code (creating images and putting them in the album boxes)
    }

Upvotes: 2

Views: 3048

Answers (1)

Fabrizio Calderan
Fabrizio Calderan

Reputation: 123377

you have to loop the $('.hiddenAlbumNames') jQuery collection to get the values of all your input

$('.hiddenAlbumNames').each(function() {
       console.log( $(this).val() );
       /* rest of the code for each name retrieved */
})

Upvotes: 6

Related Questions