Javascript examples for jQuery Method and Property:attr
Get the value of the href attribute in a link:
<!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>