
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Use attr() Method in jQuery to Get Attribute Value
The jQuery attr() method is used to get the value of an attribute, with the attribute, for example, href. Mention the attribute as the parameter of the attr() method.
You can try to run the following code to learn how to use the attr() method to get the value of an attribute:
Example
<html> <head> <title>Selector Example</title> <script src = "https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script> $(document).ready(function(){ $("button").click(function(){ alert($("#tpoint").attr("href")); }); }); </script> </head> <body> <p><a href="https://www.tutorialspoint.com" id="tpoint"> Website tutorialspoint</a></p> <button>Show complete link</button> </body> </html>
Advertisements