So i read this question and i want to use its answer, however as overwrites everything i put in, if I for example add a red div it vanish. How can i make this javascript work well with my other html...
var newHTML = replaceWithImgLinks($(document.body).text());
$(document.body).html(newHTML);
function replaceWithImgLinks(txt) {
var linkRegex = /([-a-zA-Z0-9@:%_\+.~#?&//=]{2,256}\.[a-z]{2,4}\b(\/[-a-zA-Z0-9@:%_\+.~#?&//=]*)?(?:jpg|jpeg|gif|png))/gi;
var replacement = '<a href="$1" target="_blank"><img class="sml" src="$1" /></a><br />'
return txt.replace(linkRegex, replacement);
}
(Im stupid and my javascript knowledge is not the best) if you could explain why it doesn't work aswell i would be very satisfied.:)
Here is a fiddle aswell so you can see my problem:
So what I am trying to do is so all the imgs srcs in my div is changed to images "instead of the whole body i think"