How to change the href Attribute value for a Hyperlink with little bit jQuery ?

When coding with jQuery, at some point or the other you would want to modify the source of a particular hyperlink using jQuery. In this micro post we will help you with some simple code snippets on how you can change the href attribute of a given by applying just a tricky jQuery logic. The only thing that you need to be careful about with this is that you will have to be particular with you selector when you are targeting a link otherwise the possibility is that your other web pages will be overridden. For instance, let us suppose that there is a hyperlink that points to orkut.com and now your project requires you to change the hyperlink to facebook.com then you can do this by employing the simple code snippet shown below:

1
$("a [href="http://www.orkut.com/"]").attr ("href", "http://www.facebook.com/")

However if you would like to change all the hyperlinks on your webpage to point to a custom link say yahoo then the below code snippet will help you modify this:

1
$("a”).attr ("href", "http://www.yahoo.com/")

For jQuery version above 1.6, you can use prop () instead of attr () to change the href of a hyperlink, so the above code for higher versions can be replaced as:

1
$("a”).prop ("href", "http://www.yahoo.com/")
WordPress Speed Test

Recently Published

»

8 Ways the Right Ecommerce Platform Makes Your Business Perform Better

Starting your own ecommerce store is an exciting experience, but ...

»

The SSL certificates and why are they essential for sites

What are SSL and its purpose? SSL is a modern technology that is ...

»

Entering Into M-Commerce as a Small Business

According to a December 2016 Business Insider article, the U.S. ...

»

How to Convert More Traffic Quickly and Easily

If you’ve got a blog that gets plenty of traffic but ...

»

Strengthen Workplace Productivity with Live Chat Software

Live chat has become an important part of every company’s customer ...

»

How More Powerful Smartphones Are Making Websites Load Faster

Smartphone speeds keep accelerating. Last October, Qualcomm joined ...

»

The Most Effective Method To Present A Logo Plan

The Most well-known creators’ battles are and how they are ...

»

Sure Guide for Improving Your WP Site Accessibility

This article compiles some best practices to optimize a WordPress ...

»

9 Social Media and Marketing Tools Recommended for a Business

A business is set up to have a profit by delivering a product or a ...