I am trying to scan my page on document load and convert all links as hyperlinks. This is saying ‘x’ is null. Can you suggest me how to do this in jquery. I am not sure if .replaceWith works
var x = document.getElementById('body');
x.innerHTML = x.innerHTML.replace(/(http:\/\/[^ ]+)/g,'<a href="$1">$1</a>/');
You already have access to the body via:
No need for a method.
Though there are better ways to create links than to destroy and recreate the entire DOM. Also, this will affect elements that currently have an
hrefattribute starting withhttp.EDIT: This is a less destructive way to accomplish what you want:
Example: http://jsfiddle.net/dVsqe/
Or no jQuery:
Example: http://jsfiddle.net/dVsqe/2/