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

  • SEARCH
  • Home
  • 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 4027330
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T11:05:01+00:00 2026-05-20T11:05:01+00:00

HTML: <a href=/>1</a> // link to http://site.com <a href=/section/page/>2/a> // link to http://site.com/section/page/ <a

  • 0

HTML:

<a href="/">1</a> // link to http://site.com
<a href="/section/page/">2/a> // link to http://site.com/section/page/
<a href="http://site.com/">3</a>
<a href="../gallery/1/">4</a> // link to http://site.com/gallery/1/

JS:

$("a").live('click', function(){
    var url = $(this).attr("href");
    //do something
});

How to convert relative path (var url) to absolute by jQuery?

Script should do nothing, if it is already an absolute path.

Thanks.

  • 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-20T11:05:02+00:00Added an answer on May 20, 2026 at 11:05 am

    I’m pretty sure that if you use the href property instead of getting the attribute, you’ll have a full url with domain:

    $("a").live('click', function(){
        var url = this.href;    // use the property instead of attribute
        //do something
    });
    

    As noted in the question linked by @Phrogz, it sounds as though there are issues with IE6.

    If you need to support it, you may need to build the href from the different parts like this.host and this.pathname. Those properties are supported by IE6. There are others you could use too, but you’d need to verify support.

    jquery live() function deprecated in version 1.7 and removed from 1.9 so use alternate on():

    $("a").on('click', function(){
        var url = this.href;    // use the property instead of attribute
        //do something
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is html: <a href=http://site.com/any/different/folders/picture_name.jpg>Go and win</a> <a href=http://site.com/not/similar/links/some_other_name.png>Go and win</a> How to add
Here is html : <a href=http://site.com/any/different/folders/picture_name.jpg>Go and win</a> <a href=http://site.com/not/similar/links/some_other_name.png>Go and win</a> How to
I have that code var p = document.createElement('p'); var a = document.createElement('a'); $(a).attr('href', 'http://www.my-site.com');
I use html attribute title to set some hints like this: <a href... title=Go
there is a script in my html tag <script type=text/javascript> function setTaxDisplay(display) { window.location.href
How do i grab the link href (under the published node) from this xml:
So i wanted to make some pretty buttons like http://www.oscaralexander.com/tutorials/how-to-make-sexy-buttons-with-css.html and everything is working
Let my site be http://cars.com I have links on my site, to http://girls.com ,
I have this code which getting html code of page and than replace all
I am trying to write a RegEx rule to find all a href HTML

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.