On Apr 15, 2007, at 8:10 AM, boermans wrote:
Hi all,
I'm attempting to write a script which makes changes to image
positioning depending on attributes of previous images within a
portion of a document. To do so I'm looking for a way to select the
previous image relative to each image in the order in which they
appear in the document.
Using .prev() would make this simple if the images were all in the one
paragraph. Some are, some not. Regardless, for each image in turn, I
want to check certain attributes of the previous image.
Thanks in advance for your ideas!
Hi there,
Not sure how you're getting the current image, but if you're doing it
based on some kind of an event, like onclick, you could get the
previous image's attribute like so:
$('img').click(function() {
var prevImg = $('img').index(this) - 1;
$('img:eq(' + prevImg +')').attr('someattribute');
});
Or you could do a .each() like Glen suggested.
Hope that helps.
--Karl
_________________
Karl Swedberg
www.englishrules.com
www.learningjquery.com