Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You already have access to the body via:</p> <pre><code>var x = document.body; </code></pre> <p>No need for a method.</p> <p>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 <code>href</code> attribute starting with <code>http</code>.</p> <hr> <p><strong>EDIT:</strong> <em>This is a less destructive way to accomplish what you want:</em></p> <pre><code>var re = /(http:\/\/[^ ]+)/g; function createLinks( els ) { $(els).contents().each( function() { if( this.nodeType === 1 &amp;&amp; this.nodeName !== 'script' ) { createLinks( this ); } else if( this.nodeType === 3 &amp;&amp; this.data.match( re ) ) { var markup = this.data.replace( re, '&lt;a href="$1"&gt;$1&lt;/a&gt;' ); $( this ).replaceWith( markup ); } }); } createLinks( document.body ); </code></pre> <p><strong>Example:</strong> <a href="http://jsfiddle.net/dVsqe/" rel="nofollow">http://jsfiddle.net/dVsqe/</a></p> <hr> <p>Or no jQuery:</p> <pre><code>var re = /(http:\/\/[^ ]+)/g; var temp = document.createElement('div'); function createLinks( els ) { var nodes = els.childNodes, node; for( var i = 0; i &lt; nodes.length; i++ ) { node = nodes[ i ]; if( node.nodeType === 1 &amp;&amp; node.nodeName !== 'script' ) { createLinks( node ); } else if( node.nodeType === 3 &amp;&amp; node.data.match( re ) ) { temp.innerHTML = node.data.replace( re, '&lt;a href="$1"&gt;$1&lt;/a&gt;' ); while( temp.firstChild ) { node.parentNode.insertBefore( temp.firstChild, node ); } node.parentNode.removeChild( node ); } }; } createLinks( document.body ); </code></pre> <p><strong>Example:</strong> <a href="http://jsfiddle.net/dVsqe/2/" rel="nofollow">http://jsfiddle.net/dVsqe/2/</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload