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

  • Home
  • SEARCH
  • 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 7993761
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T13:56:53+00:00 2026-06-04T13:56:53+00:00

I set the href -Attribute of an <a …> -Tag dynamically in a project.

  • 0

I set the href-Attribute of an <a ...>-Tag dynamically in a project. At some other point, I check the <a>‘s DOM-Property called hostname, in order to figure out whether or not it’s an internal link.

Basically, this is what happens.

<!--HTML-->
<a id="my" href="/my/first/link">MyLink</a>
<div id="log"></div>

And JS is:

// js
var a = document.getElementById( 'my' ),
    log = document.getElementById( 'log' );

log.innerHTML += a.hostname + '<br/>';

a.setAttribute('href',"/my/other/link");
log.innerHTML += a.hostname;

(cf. also this fiddle: http://jsfiddle.net/RurQT/ )

As I set d.href to a relative path, I expect d.hostname to be unchanged – so the log-Div contains the same Hostname twice. This is correct in FF and Chrome.

However, InternetExplorer 7, 8 and 9 all insist that the second time, the hostname is empty.

I am especially confused, because the first link has been relative all along! I don’t have any <base href> set, btw.

I would greatly appreciate any suggestion how I can make InternetExplorer update the “hostname”-Property of the a-DOM-Element.

  • 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. Editorial Team
    Editorial Team
    2026-06-04T13:56:55+00:00Added an answer on June 4, 2026 at 1:56 pm

    You’ll have to stash and re-set it it seems:

    var d = document.getElementById( 'my' ),
    var h = d.hostname
    d.setAttribute('href',"/my/other/link");
    d.hostname = h
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to set the href attribute of a link to point to a
I use html attribute title to set some hints like this: <a href... title=Go
I've got a .net button that has an href attribute value set to javascript:WebForm_DoPostBackWithOptions(new
Every time I put an inline tag on the link's href attribute it somehow
If I create an HTML anchor tag and set the disabled attribute to true,
I have a set of HTML files with illegal syntax in the href attribute
I have a WebBrowser control and try to set onclick and href attributes on
How can I set an a href that is both a link to and
so I have this code for tabs in jquery, the href is set to
When would you set location to a URL string versus setting location.href ? location

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.