Skip to main content

Bug Tracker

Side navigation

#8805 closed bug (patchwelcome)

Opened April 07, 2011 03:29PM UTC

Closed April 09, 2011 07:36PM UTC

Last modified May 26, 2011 08:31PM UTC

Internet Explorer changes link text when changing the href

Reported by: Owned by:
Priority: low Milestone:
Component: attributes Version: 1.5.2
Keywords: Cc:
Blocked by: Blocking:

Today I came across a IE bug and wanted to ask if we could apply a generic workaround to jquery.

Here is the snipped which cases Internet Explorer to change the text when changing a href attribute:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
        <title>Bug report</title>
        <script type="text/javascript" src="jquery-1.5.2.js"></script>
        <a href="#"> </a>
        <script type="text/javascript">
$(window).load(function() {
    $('a').attr("href", "");

The text node should be, but is "".

My workaround: set the href first, then set the text node, but that is not a generic solution!

generic workaround is explained at <a href="">stackoverflow</a>. Temp. store the text node and restore it after setting the href attribute.

Attachments (0)
Change History (7)

Changed April 07, 2011 03:38PM UTC by timmywil comment:1

owner: →
status: newpending

Thanks for taking the time to contribute to the jQuery project! Please provide a reduced test case on to help us assess your ticket. I'm not sure I understand what the problem is here.

Changed April 09, 2011 10:08AM UTC by comment:2

status: pendingnew

Sorry, here is the jsFiddle.

Affected jQuery versions: 1.4.2 - 1.5.2

Affected Browser: Internet Explorer

Not affected Browser: Chrome, Safari, Firefox

Affected operating system: Windows

HowTo reproduce the issue: open jsFiddle in Internet Explorer

Expect to happen: result in jsFiddle should be

<a  id="testNode" href=""></a>

but in Internet Explorer it is:

<a id="testNode" href=""></a>

Changed April 09, 2011 07:36PM UTC by timmywil comment:3

component: unfiledattributes
priority: undecidedlow
resolution: → patchwelcome
status: newclosed

Confirmed. I've looked into fixing this and I'm not sure it is worth the amount of code this requires. I tried setting the attribute every way I could think of and if I'm right, it would mean another test in support.js and at least 6-7 lines in attributes.js because it would mean a setter hook for href that temporarily saves out the anchors contents then reinserts them after setting the href.

IE changes the text only in certain cases. When setting the href to "", I could reproduce the bug with the text set to "", but not when set to "jquery". This is admittedly odd and frustrating behavior, but you probably don't want to set the text to .org when the href is going to .com. I suggest setting the text after the href for now and if someone can think of a way to add a fix for this without inflating the code too much, I think we would welcome a patch.

Changed April 12, 2011 02:27PM UTC by comment:4

small update:

Affected Browser: Internet Explorer <= 8

Not affected Browser: Chrome, Safari, Firefox, Internet Explorer = 9

Changed May 26, 2011 03:24PM UTC by timmywil comment:5

#9428 is a duplicate of this ticket.

Changed May 26, 2011 07:51PM UTC by dmethvin comment:6

_comment0: Hmmm, IE<9 only seems to misbehave if the '''attribute''' is set, and not the '''property'''. So one workaround is to use: \ {{{ \ $("#whatever").prop("href", ""); \ }}} \ As long as you don't plan to serialize the HTML of the link (via `.innerHTML` or `.clone()`) there shouldn't be any negative impacts. \ 1306442171702608

Disregard ...

Here is a fiddle showing the problem in pure DOM in IE:

Changed May 26, 2011 08:31PM UTC by timmywil comment:7

It seems it still has the same behavior when setting the property. This bug has been present since jQuery 1.0. I suggest setting the text after setting the href. The bug does not occur if text is not altered with javascript beforehand.