7

I'm trying to create a simple Flickr plugin via the API to show a gallery of photo sets . The way I'd like it to work is something like this:

    <div id="72157634235266773" class="thumb"></div>

    <div id="72157633471728555" class="thumb"></div>

and the jQuery plugin would iterate through and find all div's with class="thumb" and plug the id value - which is the flickr photoset id - into the code to render the thumbnail and accompanying image files for the gallery.

This fiddle has my code: http://jsfiddle.net/eBGVV/3/

See how it places two of the same thumbnail images next to each other under "Photo Set 1"?

The desired result would be the correct thumb under each Photo Set 1 and 2.

I know there is a problem with how I'm using the .each but I'm not sure what?

Thanks!

Erik Berger
  • 599
  • 1
  • 10
  • 24

1 Answers1

15

Change the first four lines so the $(document).ready nests everything, and within the each function, you only want to refer to the current iterated instance of the .thumb using $(this)

$(document).ready(function () {
     $('.thumb').each(function () {
          var PhotoSetID = $(this).attr("id");
Herman Tran
  • 1,581
  • 2
  • 12
  • 19
  • Wow! That did the trick. Thank you so much. Here is the correct version: http://jsfiddle.net/eBGVV/4/. Anyone out there that reads this please feel free to use. Just please get your own flickr api key! – Erik Berger Jun 23 '13 at 06:16
  • would you consider helping me with a related question? http://stackoverflow.com/questions/17262435/jquery-flickr-plugin-with-colorbox-gallery-displays-previous-photos – Erik Berger Jun 23 '13 at 16:33