- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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 change the value of an attribute using jQuery?
The jQuery attr() method is used to get the value of an attribute. It can also be used to change the value. In the example, we will change the attribute value tutorialspoint.com to tutorialspoint.com/java.
You can try to run the following code to learn how to change the value of an attribute using jQuery −
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(){ $("#tpoint").attr("href", "https://www.tutorialspoint.com/java"); }); }); </script> </head> <body> <p><a href="https://www.tutorialspoint.com" id="tpoint">tutorialspoint.com</a></p> <button>Change attribute value</button> <p>The value of above link will change on clicking the above button. Check before and after clicking the link.</p> </body> </html>
- Related Articles
- How to set new value for an attribute using jQuery?
- How to change the value of an attribute in javascript?
- Change input type value attribute in jQuery
- How to get an attribute value in jQuery?
- How to change the href attribute for a hyperlink using jQuery?
- How to change the src attribute of an img element in JavaScript / jQuery?
- How to find an element based on a data-attribute value using jQuery
- How to use attr() method in jQuery to get the value of an attribute?
- 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?
- How to remove an attribute from each tag using jQuery?
- How to change text inside an element using jQuery?
- jQuery [attribute!=value] Selector
- How to use jQuery to get the value of HTML attribute of elements?

Advertisements