Search code examples
javascriptjqueryfancybox

Make each array item a separate link


I need help in creating links from an array. I need create a personalized link for every item in the array

Here's the code:

caption: function(instance, item) {
    var caption, link, collectTags, tags;
    caption = $(this).data('caption');
    link = '<a href="' + item.src + '">Download image</a>';
    collectTags = $(this).parent().attr("class").split(' ');
    tags = $.each(function() {
        '<a href="' + collectTags + '">' + collectTags + '</a>'
    });
    return (caption ? caption + '<br />' : '') + link + '<br/>' + tags;
}

Solution

  • your code may be like this,you called $.each without passing an array.

    caption : function( instance, item ) {
        var caption, link, collectTags, tags;
    
        caption = $(this).data('caption');
        link    = '<a href="' + item.src + '">Download image</a>';
        collectTags =   $(this).parent().attr("class").split(' ');
        tags = $.map(collectTags,function(it){ return '<a href="' + it + '">'+ it +'</a>';});
    
        return (caption ? caption + '<br />' : '') + link + '<br/>' + tags;
    
    }