Get the value of the href attribute in a link: - Javascript jQuery Method and Property

Javascript examples for jQuery Method and Property:attr

Description

Get the value of the href attribute in a link:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
    $("button").click(function(){
        console.log($("#myId").attr("href"));
    });// w  w w . ja va  2  s .  c o  m
});
</script>
</head>
<body>

<p><a href="http://java2s.com" id="myId">java2s.com</a></p>

<button>Show href Value</button>

</body>
</html>

Related Tutorials