jQuery addClass example
Change class name on click in jQuery
by manu v
HTML
<p id="GFG_UP" style="font-size: 15px;
font-weight: bold;">
</p>
<button onclick="urlify()">
click here
</button>
<p id="GFG_DOWN" style="color:green;
font-size: 20px;
font-weight: bold;">
</p>
JavaScript
function urlify(text) {
var urlRegex = /(((https?:\/\/)|(www\.))[^\s]+)/g;
//var urlRegex = /(https?:\/\/[^\s]+)/g;
return text.replace(urlRegex, function(url,b,c) {
var url2 = (c == 'www.') ? 'http://' +url : url;
return '<a href="' +url2+ '" target="_blank">' + url + '</a>';
})
}
var text = "Find me at www.example.com and also at http://stackoverflow.com";
var html = urlify(text);
console.log(html)