Show Output
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>jQuery Get an Element's Attribute Value</title> <script src="https://code.jquery.com/jquery-3.5.1.min.js"></script> <script> $(document).ready(function(){ $(".btn-one").click(function(){ var str = $("a").attr("href"); alert(str); }); $(".btn-two").click(function(){ var str = $("img#sky").attr("alt"); alert(str); }); }); </script> </head> <body> <button type="button" class="btn-one">Get Link's HREF Attribute</button> <button type="button" class="btn-two">Get Image ALT Attribute</button> <p><a href="https://www.appwang.com/">Tutorial Republic</a></p> <img id="sky" src="/examples/images/sky.jpg" alt="Cloudy Sky"> </body> </html>