Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4021690
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:22:58+00:00 2026-05-20T10:22:58+00:00

UPDATE: Answer #3 ended up working the best. I most likely did something wrong

  • 0

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):

  1. http://dl.dropbox.com/u/1007716/spanToUrl/test01.html
  2. http://dl.dropbox.com/u/1007716/spanToUrl/test02.html
  3. http://dl.dropbox.com/u/1007716/spanToUrl/test03.html (winner)
  4. http://dl.dropbox.com/u/1007716/spanToUrl/test04.html
  5. http://dl.dropbox.com/u/1007716/spanToUrl/test05.html
  6. 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>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T10:22:59+00:00Added an answer on May 20, 2026 at 10:22 am

    Try this:

    $('.sampleClass span').replaceWith(function() {
        var url = $.trim($(this).text());
        return '<a href="' + url + '" target="_blank">' + url + '</a>';
    });
    

    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 add first() to the selector chain, like this:

    $('.sampleClass span').first().replaceWith( /* ... */ );
    

    If it is rather the entire column that contains links, than you’ll want to operate on every other match. Do this by appending :even to your selector, like this:

    $('.sampleClass span:even').first().replaceWith( /* ... */ );
    

    (Yes, :even and not :odd to select the 1st, 3rd, &c. elements, because of 0-based indexing.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Update (21st Sept 2016) - Thanks to Digbyswift for commenting that this solution still
I have a pet project that is an online game, the entire game engine
I sometimes run into the problem of labels in TreeForm being unreadable because of
I'm making an AJAX call which returns XML data, and this is my 'success:'
I am making an application that deals with vehicles. I need two DropDownLists: Makes:
I am making multiple calls to ObjectContext.ExecuteStoreCommand with different commands and different parameters, although
I'm running Ubuntu 8.04 and I ran the command: $ ctags -R --c++-kinds=+p --fields=+iaS
I'm trying to modify my test so that any database work is rolled back
I have a categories model made with the fantastic awesome_nested set. I have successfully
I am generating reports using HTML and I am using CSS to control the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.