So basically what I want to do is grab links to images within a page and convert them to images. Right now, I have code that will grab any link within a post on the forums and converts them to images, but I want it more specific than that. I want to be able to grab images using the main 4 web image extensions (.jpg, .gif, .png, .bmp). I’m new to jQuery so I’d really love some help on this. Here’s my code that I have so far:
(function($) {
if ($('#nav a[href*="/forum/3828932/"]').length && location.href.indexOf('/1/') !== -1) {
$('td.c_post:eq(0) a').each(function () {
link = $(this).attr('href');
$(this).html('<a href="' + link + '"><img src="' + link + '" alt="Icon" /></a>')
});
}
})(jQuery);
You can try to use the
ends-withselector to select anchor with href ends with those valueshttp://api.jquery.com/attribute-ends-with-selector/
and multiple selector
http://api.jquery.com/multiple-selector/
so your selector may look something like