- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to use attr() method in jQuery to get the value of an attribute?
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>
- Related Articles
- How to get an attribute value in jQuery?
- How to use jQuery to get the value of HTML attribute of elements?
- How to get value of data attribute and use it in jQuery?
- How to get the value of id attribute in jQuery?
- How to get the value of src attribute in jQuery?
- How to get the value of custom attribute in jQuery?
- jQuery attr() Method
- How to change the value of an attribute using jQuery?
- How to use jQuery hasAttribute() method to see if there is an attribute on an element?
- How to use GET method to send data in jQuery Ajax?
- How to set new value for an attribute using jQuery?
- How to get an attribute value of an element in Selenium Webdriver?
- How to use *= operator in jQuery attribute selector?
- How to use input readonly attribute in jQuery?
- How to use OR Operation in jQuery Attribute Selectors?

Advertisements