11

I'm having trouble in getting the exact value of href only. Here is the code:

Link:
<a href="monthly"></a>

Script:
'a': function(target, process){
    if(process == "stripe"){
        document.location.href = "/accounts/stripe/payment"+target[0].href;
    }else{
        ......
    }
},

If I run this the output will be:

http://localhost:8000/accounts/stripe/paymenthttp://localhost:8000/monthly/

Notice that the localhost is duplicating. How to get only the "monthly" in href without that localhost? I try target only but it's undefined. I try target[1] but it's not working.

catherine
  • 22,492
  • 12
  • 61
  • 85

2 Answers2

18

Try target[0].getAttribute("href") to get the literal attribute's content.

Niet the Dark Absol
  • 320,036
  • 81
  • 464
  • 592
5

It's a little known (maybe) fact that most browsers convert Anchor node elements into Location objects as well. So you can access all parts available to Location too;

 document.location.href = "/accounts/stripe/payment"+target[0].pathname;
Explosion Pills
  • 188,624
  • 52
  • 326
  • 405