Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 57115
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T17:38:27+00:00 2026-05-10T17:38:27+00:00

How can you change the href attribute (link target) for a hyperlink using jQuery?

  • 0

How can you change the href attribute (link target) for a hyperlink using jQuery?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T17:38:27+00:00Added an answer on May 10, 2026 at 5:38 pm

    Using

    $('a').attr('href', 'http://www.google.com/') 

    will modify the href of all hyperlinks to point to Google. You probably want a somewhat more refined selector though. For instance, if you have a mix of link source (hyperlink) and link target (a.k.a. ‘anchor’) anchor tags:

    <a name='MyLinks'></a> <a href='http://www.codeproject.com/'>The CodeProject</a> 

    …Then you probably don’t want to accidentally add href attributes to them. For safety then, we can specify that our selector will only match <a> tags with an existing href attribute:

    $('a[href]') //... 

    Of course, you’ll probably have something more interesting in mind. If you want to match an anchor with a specific existing href, you might use something like this:

    $('a[href='http://www.google.com/']').attr('href', 'http://www.live.com/') 

    This will find links where the href exactly matches the string http://www.google.com/. A more involved task might be matching, then updating only part of the href:

    $('a[href^='http://stackoverflow.com']')    .each(function()    {        this.href = this.href.replace(/^http:\/\/beta\.stackoverflow\.com/,           'http://stackoverflow.com');    }); 

    The first part selects only links where the href starts with http://stackoverflow.com. Then, a function is defined that uses a simple regular expression to replace this part of the URL with a new one. Note the flexibility this gives you – any sort of modification to the link could be done here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 101k
  • Answers 101k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer They would be differnt because they are two differnt products… May 11, 2026 at 8:09 pm
  • Editorial Team
    Editorial Team added an answer Date objects are also Comparable, so you could construct a… May 11, 2026 at 8:09 pm
  • Editorial Team
    Editorial Team added an answer I personally would not want ColdFusion to include those tags,… May 11, 2026 at 8:09 pm

Related Questions

I'm currently coding a French website. There's a schedule page, where a link on
How can you change the default tests path in Makefile.PL from the default value
The German website nandoo.net offers the possibility to shorten a news article. If you
I know you can change the frame size in the .emacs file with set-frame-width

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.