
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
Set New Value for an Attribute Using jQuery
The jQuery attr() method is used to get the value of an attribute. It can also be used to set new value. We will set new value of attribute href to tutorialspoint.com/html5 from tutorialspoint.com/css.
You can try to run the following code to learn how to set new value for an attribute in 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/html5"); }); }); </script> </head> <body> <p><a href="https://www.tutorialspoint.com/css" id="tpoint">Tutorialspoint</a></p> <button>Set new value</button> <p>The value of above link will change on clicking the above button. This will set a new value for the attribute. Check before and after button click.</p> </body> </html>
Advertisements