mercredi 8 mars 2017

If..else statement based off array function results

What I need want to happen is to have different URLs be provided based off of what the array function result is. Basically, if collectTags is equal to "church" or "concert" it links to A.com else it links to B.com.

Here's the code I currently have:

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){ if(collectTags === "church"){ return '<a href="A.com' + it + '">'+ it +'</a>'} else{return '<a href="B.com' + it + '">'+ it +'</a>'};});

    return (caption ? caption + '<br />' : '') + link + '<br/>' + tags.slice(1);

}

Aucun commentaire:

Enregistrer un commentaire