Bug Tracker

Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#7117 closed bug (fixed)

In the created object returns incorrect data href attribute

Reported by: t_e_m_p_v_s Owned by:
Priority: low Milestone: 1.4.3
Component: attributes Version: 1.4.2
Keywords: Cc:
Blocked by: Blocking:


Creating an object: a = $('<a href="#' + url + '">' + text + '</a>'); In IE7 (maybe another IE) returns incorrect data of href attribute href = a.attr('href'); Firefox: '#abc' IE7: 'http://host/page#abc'

Change History (4)

comment:1 Changed 10 years ago by addyosmani

need: ReviewPatch
Priority: highlow

Here is a live test case replicating the above ticket:


The issue does not appear to effect IE8 or IE9, but as the original submission mentions, in IE7 (and in IE6) rather than just the value of the href being set to '#abc' it is actually appending the entire base URL and treating it more like a complete anchor reference (eg. http://www.site.com/#hash).

Whilst this is something that could be corrected with special-casing, I'm flagging for an additional review and patch as the behavior mentioned in the ticket appears to be quite consistent in my testing.

comment:2 Changed 10 years ago by snover


Updated test case

It appears that only <a> elements generated programmatically using strings exhibit this problem. Elements that are generated like $('<a>', { href: '#foo' }) work properly, as do elements that existed in the document when it was loaded.

Short of scanning all strings passed to jQuery and html for anchors and manually resetting their attributes, there is almost certainly no way that jQuery can work around this issue, as IE is irreparably modifying the href property when building elements from strings. You can see this by inspecting the generated markup (the href attribute magically becomes absolute). As a result, this is probably only going to be a documentation fix.

comment:3 Changed 10 years ago by snover

Resolution: fixed
Status: newclosed

Updated .html and jQuery() documentation.

comment:4 Changed 10 years ago by snover

#7172 is a duplicate of this ticket.

Note: See TracTickets for help on using tickets.