We can use the jQuery attribute method to set or change attribute values of an html element.
In this example, we have a text link with an
href attribute set to youaccel.com.
If we click the "Change Link URL" button, the
href attribute resets to a new link: youaccel.com/aboutus.php.
Let's take a look at our html code to see how this was done.
<p><a href="http://www.youaccel.com" id="ya">youaccel.com</a></p>
<button>Change Link URL</button>
<body> tags, we can see the button element and also the link. The
href attribute in the a element is set to youaccel.com. The id for the a element is set to ya.
In our script, we have attached a
click event on the button. Once the button is clicked, the element with id ya, resets its
href attribute to youaccel.com/aboutus.php.