Exercise:
Alert the URL address of the link.
Hint
Hint: Use the attr() method.
Edit This Code:
See Result »
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script> <script> $(document).ready(function(){ // add code here }); </script> </head> <body> <a href="../index.html">W3Schools</a> </body> </html>
Result:
Show Answer
Correct Code:
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script> <script> $(document).ready(function(){ alert($("a").attr("href")); }); </script> </head> <body> <a href="../index.html">W3Schools</a> </body> </html>
Correct Result:
Hide Answer
Privacy Policy