As I said, I am new to JQuery and javascript in general, so I am not really aware of the "normal" ways. I am trying to create code that is accessible and understandable to a wider group of people, and it seems a good way to do that is to use custom functions related to the job at hand. That way I can keep the function calls separated from their messy details. If there is a different approach, I am not aware of it.
As for the each() function, thank you, I will try out your suggestion. Andrew On Aug 16, 3:47 pm, MorningZ <morni...@gmail.com> wrote: > "//CREATE EACH THUMBNAIL > $(this).find("thumbpath").each(i).createThumb > (); <<<-------------- > I think I am using "i" incorrectly " > > No, that is not correct, it would be like: > > $(this).find("thumbpath").each(function(i) { > $(this).createThumb(i); > > }); > > and need to change this as well > > $.fn.createThumb = function(i) { > > not sure why that would need to be turned into a plugin/extension > instead of just a normal JS event/function > > On Aug 16, 2:50 pm, "andrew.croce" <andrew.cr...@gmail.com> wrote: > > > Hi, > > I am pretty new to this so please excuse problems that might seem > > obvious...they're not necessarily obvious to me yet. > > I am writing some basic image gallery functionality, using my own > > defined jquery functions. I am trying to use .each() to loop through > > the "image" tags of an xml file, and create a thumbnail for each of > > them. I want to catch the index of each iteration to create a > > variable I can use to match my thumbs with my full-size images... > > > $.fn.createGallery = function(){ > > //START GALLERY OUTPUT STRING > > galleryOutputHTML = ""; > > galleryOutputHTML += "<div class='thumbs'>"; > > > //CREATE EACH THUMBNAIL > > $(this).find("thumbpath").each(i).createThumb(); > > <<<-------------- > > I think I am using "i" incorrectly > > > //CLOSE GALLERY OUTPUT STRING AND POPULATE GALLERY > > galleryOutputHTML += "</div>"; > > $("#gallery_area").append(galleryOutputHTML); > > }; > > > .......then here is the .createThumb() function called above...... > > > $.fn.createThumb = function(){ > > current_imageXML = > > $(current_galleryXML).find("image[id="i+1"]"); > > var thumbPath = $(this).text(); > > var thumbAlt = > > $(current_imageXML).find("image_title").text(); > > thumbOutputHTML = ""; > > thumbOutputHTML += "<img class='gallery_thumb' > > id="i+1" > > src="+thumbPath+" alt="+thumbAlt+"/>"; > > > //ADD THUMB OUTPUT TO GALLERY OUTPUT > > galleryOutputHTML += thumbOutputHTML; > > }; > > > What I am attempting to do is catch the index of the each loop (i) and > > reference it as an element id in the html output, so that the > > thumbnails are given the ids 1, 2, 3, etc. I am not sure I am using > > the i variable correctly with the .each() loop, and I can't find much > > documentation on how to use it when calling custom functions. > > Any suggestions would be appreciated. > > Thanks > > Andrew