JSFiddle - React, Tailwind, and code Playground

by krishna_aim24

HTML

<a href="http://www.mydomain.com/files/test1.pdf" target="_blank">My link</a> 
<a href="http://www.mydomain.com/files/test1.jpg" target="_blank">My link</a> 
<a href="http://www.mydomain.com/files/test1.nofile" target="_blank">My link</a>

JavaScript

jQuery(function() {
    jQuery("a").each(function() {
        if (jQuery(this).attr("href").indexOf("http://www.mydomain.com/files/") > -1) {
            jQuery(this).wrap("<div class='myLink'></div>");
            switch (jQuery(this).attr("href").split(".")[jQuery(this).attr("href").split(".").length - 1]) {
            case "pdf":
                jQuery(jQuery(this).parent().prepend("<img src='pdf_image_path' />"));
                jQuery(jQuery(this).parent().append("<span class='fileSize'>1.3 Mb</span>"));
                break;
            case "jpg":
                jQuery(jQuery(this).parent().prepend("<img src='jpg_image_path' />"));
                jQuery(jQuery(this).parent().append("<span class='fileSize'>1.3 Mb</span>"));
                break;
            case "png":
                jQuery(jQuery(this).parent().prepend("<img src='png_image_path' />"));
                jQuery(jQuery(this).parent().append("<span class='fileSize'>1.3 Mb</span>"));
                break;
/*
* add your more condition here
*/
            default:
                console.log("no match found");
            }
        }
    });
})