2

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)
    }
0

1 Answer 1

6

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 */
})
Sign up to request clarification or add additional context in comments.

3 Comments

val() work even for checkboxes, anyway he asked for "hidden input field"
I know that .val() work with checkboxes but it doesn't describe if it checked or not
it's a bit off-topic but if they where checkboxes he would loop checked input with $('.hiddenAlbumNames:checked')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.