Are you first timer at lazacode.org? Why not join us and start exchange your programming knowledge with everyone. Register today!

JS - Replacing URL text into clickable link

0 votes
29 views
added Dec 6, 2020 in Javascript by lcjr Second Warrant Officer (3,820 points)
$(document).ready(function() {
	$('.qa-q-view-extra').each(function(){
 		var str = $(this).html();
		// Set the regex string
		var regex = /(https?:\/\/([-\w\.]+)+(:\d+)?(\/([\w\/_\.]*(\?\S+)?)?)?)/ig
		// Replace plain text links by hyperlinks
		var replaced_text = str.replace(regex, "<a href='$1' target='_blank'>$1</a>");
		// Echo link
		$(this).html(replaced_text);
	});
});

 

Please log in or register to response this reference.

lazacode.org - Malaysia's programming knowledge sharing platform, where everyone can share their finding as reference to others.
...