- 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
jQuery attr() Method
The attr() method in jQuery is used to set or return attributes and values of the selected elements.
Syntax
The syntax is as follows −
$(selector).attr(attribute)
Example
Let us now see an example to implement the jQuery attr() method −
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script> <script> $(document).ready(function(){ $("button").click(function(){ alert("Input Type (Student Id) = " + $("input").attr("type")); }); }); </script> </head> <body> <h2>Student Details</h2> Student Id: <input type="text"><br> <button>Click me</button> <p>Click on the button above to return the type of the input.</p> </body> </html>
Output
This will produce the following output −
Click on the above button to display the type of the input text −
Advertisements