Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I suspect that I could much improve upon this, though at the minute this is the best I can offer (albeit I think that some kind of replace might work more efficiently):</p> <pre><code>var $words = $('p').text().split(' '); for (i in $words) { if ($words[i].indexOf('http://') == 0) { $words[i] = '&lt;a href="' + $words[i] + '"&gt;' + $words[i] + '&lt;/a&gt;'; } } $('p').html($words.join(' ')); </code></pre> <p><a href="http://jsfiddle.net/davidThomas/weFNA/" rel="nofollow">JS Fiddle demo</a>.</p> <p>A slightly improved version of the above (but good lord, it's ugly...):</p> <pre><code>var punctuation = ['!',"'",'"',',','.']; $('p').each( function(){ $words = $(this).text().split(' '); for (i in $words){ if ($.inArray($words[i].charAt(0),punctuation) &gt; -1 &amp;&amp; $words[i].indexOf('http://') == 1){ alert($words[i]); } else if ($.inArray($words[i].charAt($words[i].length - 1),punctuation) &gt; -1 &amp;&amp; ($words[i].indexOf('http://') == 1 || $words[i].indexOf('http://') == 0)){ $words[i] = '&lt;a href="'+$words[i].substring(0,$words[i].length-1)+'"&gt;' + $words[i].substring(0,$words[i].length-1) + '&lt;/a&gt;' + $words[i].charAt($words[i].length-1); } else if ($words[i].indexOf('http://') == 0){ $words[i] = '&lt;a href="' + $words[i] + '"&gt;' + $words[i] + '&lt;/a&gt;'; } } $(this).html($words.join(' ')); }); </code></pre> <p><a href="http://jsfiddle.net/davidThomas/weFNA/1/" rel="nofollow">JS Fiddle demo</a>.</p> <p>I'm not quite sure what to do about quoted links, though (text such as <code>"http://google.com"</code>, for example); and, honestly, I think that regex is probably the far, <em>far</em> better approach to this problem.</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