I’ve successfully made the links clickable but how do i make them revert back to their unclickable state again?
HTML
<div id="links">
http://google.com <br>
http://facebook.com <br>
http://youtube.com
</div>
<button>Toggle!</button>
JavaScript
$.fn.replaceUrl = function() {
var regexp = /((ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?)/gi;
this.each(function() {
$(this).html(
$(this).html().replace(regexp,'<a href="$1">$1</a>')
);
});
return $(this);
}
$('button').click(function(){
$('div').replaceUrl();
});
Check this fiddle: http://jsfiddle.net/2ttWS/
Code: