Link to home
Start Free TrialLog in
Avatar of tf2012
tf2012

asked on

jquery question

I'm adding a button to all gallery images on a wordpress page.

how can I get this script to apply to each .gallery-icon element on the page.. there may be hundreds in the gallery. Seems to me this should use implicit interation but it only seems to  target the first occurence.  How can I get it to apply to every matching element in the dom?

jQuery(document).ready(function($) {

			
			$(".gallery-icon a:first").after("<a href='"+$(".gallery-icon a:first").attr('href')+"' title='testing' download=''>Hello</a>");
		
});

Open in new window

SOLUTION
Avatar of Rainer Jeschor
Rainer Jeschor
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of tf2012
tf2012

ASKER

just a bunch of test images in there

http://mesotheliomacanada.ca/test-gallery-page/
Avatar of tf2012

ASKER

I'm trying to add a link (in this case 'hello') below the image.   But the loop doesn't iterate through all images, just applies the link to the first one.
Avatar of tf2012

ASKER

you can see it in there now... the hello link should be under each image with the respective href url applied but it doesn't seem to work..

My loop is loopy
Avatar of tf2012

ASKER

so quiet here now.... I guess I'll figure it out on my own, anyone have an idea?
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Here you go.

$(".gallery-icon").each(function(i,e) {
   var link = $('a:first', this);
   newLink = $('<a>').attr('href', link.attr('href')).text('Hello');
   link.after(newLink);
});

Open in new window

Avatar of tf2012

ASKER

because its the solution that worked