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?
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>");
});
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
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
My loop is loopy
ASKER
so quiet here now.... I guess I'll figure it out on my own, anyone have an idea?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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);
});
ASKER
because its the solution that worked
ASKER
http://mesotheliomacanada.ca/test-gallery-page/