9

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
  • 21,838
  • 12
  • 59
  • 79

2 Answers2

17

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

Niet the Dark Absol
  • 311,322
  • 76
  • 447
  • 566
4

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
  • 183,406
  • 48
  • 308
  • 385