Speed up development with full-stack environments for every branch.

Learn More

How to get <a> href value using jQuery

Forked from How to use the jQuery UI Slider.

9399 Runs 119630 Views 24722 Copies


pg1 45

published 4 years ago

<!doctype html>

    <title>How to get <a> href value using jQuery</title>
            text-align: center;
            font-family: arial;
            font-size: 21px;
            font-weight: bold;
            padding:5px 10px;

    This link points to <a href="http://runnable.com/">runnable.com</a><br />
    <input type="button" value="Get link's href value" class="button" /><br />
    <span id="results"></span>

    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>


        //When DOM loaded we attach click event to button
        $(document).ready(function() {

                //we select the first link 
                //then call the attr method to get back the href value
                var href = $('a:first').attr('href');

                //update the results span with the href value


Please login/signup to get access to the terminal.

Your session has timed out.

Dismiss (the page may not function properly).