Posted in jquery
5
11:22 pm, May 7, 2020

get the href value using jquery

this uses the jquery attr function to get the value of the href. this example targets the first a in the card div, so running the demo should alert you with https://kruxor.com
Rather than using alert in this example, i use sweet alert 2! looks pretty sweet :P

HTML

<div class='mydiv'>
<a href='https://kruxor.com' class='btn btn-primary mb-3'>The Link</a>
</div>
<button onclick='getHREF();' class='btn btn-primary mb-3'>Get HREF</button>

Javascript

function getHREF() {
var the_href = $('.mydiv a').attr('href');
Swal.fire(the_href);
}

View Statistics
This Week
22
This Month
150
This Year
0

No Items Found.

Add Comment
Type in a Nick Name here
 
Search Code
Search Code by entering your search text above.
Welcome

This is my test area for webdev. I keep a collection of code snippits here, mostly for my reference. Also if i find a good site, i usually add it here.

Join me on Substack if you want me to send you a collection of the things i have done or found or read for the week. Or follow me on twitter if you prefer, i dont post much but i probably should!

❤👩‍💻🕹

Random Quote
Old programmers never die; they just lose some of their functions.