Change href Attribute Of A Hyperlink Or HTML Link Using JQuery

For More Videos Visit Our YouTube Channel




Here we consider how to change the href attribute of a Hyperlink using JQuery. Suppose we have a Hyperlink as shown below.

Change href Attribute Of A Hyperlink Using JQuery, Change href Attribute Of A Hyperlink, Change href Attribute Of A Hyperlink In JQuery Or JavaScript, Change href Attribute, href Attribute Of A Hyperlink, Change href Attribute Of HTML Link, Jquery, HTML, Asp.Net, PHP

On browser, hyperlink would render as HTML Link as shown below.

Change href Attribute Of A Hyperlink Using JQuery, Change href Attribute Of A Hyperlink, Change href Attribute Of A Hyperlink In JQuery Or JavaScript, Change href Attribute, href Attribute Of A Hyperlink, Change href Attribute Of HTML Link, Jquery, HTML, Asp.Net, PHP




On Button Click, we may wants to change the href of this hyperlink. We can make use of the ID of HyperLink and Jquery attr as follows.

$(function () {
          $('#btnRedirect').click(function () {
                    $("#hyperRedirect").attr("href", "http://www.google.com");
                    return false;
          })
})



Here we first find the Hyperlink by using its ID or Class. And then href attribute value will be changed with desired one using Jquery attr. That's all, after button Click, the href of Hyperlink will be changed.