UPDATE:
Answer #3 ended up working the best. I most likely did something wrong with the other suggestions; #3 was maybe the easiest to implement. If you are curious, the example solutions that I tried can be found here (for now):
- http://dl.dropbox.com/u/1007716/spanToUrl/test01.html
- http://dl.dropbox.com/u/1007716/spanToUrl/test02.html
- http://dl.dropbox.com/u/1007716/spanToUrl/test03.html (winner)
- http://dl.dropbox.com/u/1007716/spanToUrl/test04.html
- http://dl.dropbox.com/u/1007716/spanToUrl/test05.html
- http://dl.dropbox.com/u/1007716/spanToUrl/test06.html
ORIGINAL POST:
I have a plain text website address inside a <span> tag. I’d like to change that <span> tag into a proper hyperlink with target="_blank"
I’ve put together a detailed example of what I have to work with here: http://bit.ly/spantourl
If you don’t want to click through, here is what I have:
<span>http://www.domain.com/about</span>
and I need to change that into:
<a href="http://www.domain.com/about" target="_blank">http://www.domain.com/about</a>
Try this:
There’s no need for
each, since replaceWith can iterate through multiple elements and can take a function as a parameter.Looking at your sample HTML, I see that it is only the first
<td>that contains a URL. If there is indeed only one, you can addfirst()to the selector chain, like this:If it is rather the entire column that contains links, than you’ll want to operate on every other match. Do this by appending
:evento your selector, like this:(Yes,
:evenand not:oddto select the 1st, 3rd, &c. elements, because of 0-based indexing.)