Current Textarea:
fiddle
This will replace all the links and leave the other text there as well.
$(function(){
var old = $('#event_content').val();
var news = old.replace("www.london2012.com", '<a href="http://www.rio2016.com" target="_blank">www.rio2016.com</a>');
$('#event_content').val(news);
});
I believe you are looking for something like this (click here to test this fiddle):
$('#event_content').val(
$('#event_content').val().replace(/\b(http(s|):\/\/|)(www\.\S+)/ig,
"<a href='http\$2://\$3' target='_blank'>\$3</a>"));
var link = $("#event_content");
var text = link.html();
var linktext = '<a href="' + text + '" target="_blank">' + text + '</a>'
link.html(linktext);
$(function(){
var old = $('#event_content').val();
var news = '<a href="http://'+old+'" target="_blank">'+old+'</a>';
$('#event_content').val(news);
});
Note that the <a>
will not be displayed in textarea, but instead plain text will be shown.
Demo: http://jsfiddle.net/3xEh2/1/