Thursday, 12 September 2013

Appending paragraphs to an image attribute in order? (1st to 1st, 2nd to 2nd ... nth to nth) JQUERY

Appending paragraphs to an image attribute in order? (1st to 1st, 2nd to
2nd ... nth to nth) JQUERY

I have made a division of paragraphs with information in each. I also have
a division of images.
My goal is to use jquery to append the text in each paragraph to an
attribute in each image called 'data-description'.
So the first paragraph put in the 'data-description' attribute for the
first image, and the second paragraph put in the 'data-description'
attribute for the second image, etc...
For instance this code will do it just for the first:
$('#galleria :first-child').attr('data-description', $('#descriptions
:first-child').text());
..given that the #galleria div contains the images, and the #descriptions
div contains the text.
I've attempted to use a variable which increases each time, or classes
which apply to each in sequence, or arrays, but I've had no joy.
I hope this explanation makes some sense!
I'd appreciate any thoughts, thanks.

No comments:

Post a Comment