2

I am using Galleria and I need to wrap my images that Galleria puts into a slide with a link.

I was going to use this methodology: Give the <img> a bogus title= value and then append a <a> tag around the <img>, drawing the link I need from the title= tag.

This is the code I've got so far.

$("img#gallery").this.title.appendTo("img#gallery") { });

I'm trying to get the script to loop through all of the images and append the html.

I also don't know if I should be using .appendTo or .before and .after

3 Answers 3

2

That approach will work. You're looking for the wrap function:

var title = $('#test').attr('title');

$('#test').wrap('<a href="'+title+'" />');

This $.each will let you iterate through a series:

<img src="" class="test" alt="test" title="http://www.google.com" />
<img src="" class="test" alt="test" title="http://www.yahoo.com" />

$.each($(".test"), function() {
    var title = $(this).attr('title');
    $(this).wrap('<a href="'+title+'" />');
});
Sign up to request clarification or add additional context in comments.

Comments

0

You could just listen for a click on the entire thing and then figure out if an image was clicked and if so which image and then change the location object.

1 Comment

I understand the theory, but what are the functions that would execute that?
0

Use $.each to iterate through all the images you want to wrap and then use

$('img#gallery').wrap('<a href='whatever'>) 

to wrap it. It will automatically close the A tag.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.