Get full URL of the href

1

I have the following code that when pressing a <a href I get the url of this one:

<a href="http://localhost/uno/dos.zip">DESCARGAR</a>

and jQuery

$('a').click(function(event) {
  var url = $('a').attr('href');
  alert(url);
});

The problem is this: when I press the link in the index.php page that I'm doing, when I press the jQuery function that shows a url is executed, but this function takes only the value of link and not the entire url link that is in <a href more above.

Is there any other option apart from href?

    
asked by dogdark 21.11.2017 в 22:30
source

1 answer

2

Check your code because the one you use should show you the full url.

Here is the working example:

$('a').click(function(event) {
  var url = $('a').attr('href');
  alert(url);
  event.preventDefault();
});
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script>

<a href="http://localhost/uno/dos">DESCARGAR</a>
    
answered by 21.11.2017 / 22:33
source