How to set new value for an attribute using jQuery?

jQueryWeb DevelopmentFront End Technology

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 from

You can try to run the following code to learn how to set new value for an attribute in jQuery −


Live Demo

      <title>Selector Example</title>
      <script src = ""></script>
               $("#tpoint").attr("href", "");
      <p><a href="" 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>
Published on 09-Dec-2017 16:22:57