Skip to main content

Bug Tracker

Side navigation

#12048 closed bug (fixed)

Opened July 10, 2012 11:15AM UTC

Closed October 20, 2012 07:30PM UTC

[IE6/7/8] xml set attribute

Reported by: Owned by: saiwong
Priority: low Milestone: 1.9
Component: attributes Version: 1.8b1
Keywords: ie6 ie7 ie8 Cc:
Blocked by: Blocking:

On line 2572:

// Use this for any attribute in IE6/7
nodeHook =
var ret = elem.getAttributeNode( name );
if ( !ret ) {
  ret = document.createAttribute( name );
  elem.setAttributeNode( ret );

if elem is XML element,you create HTML attribute and set it on XML element- type mismatch exception.

Using elem.ownerDocument would be more correct IMHO.

Attachments (0)
Change History (18)

Changed July 10, 2012 01:48PM UTC by dmethvin comment:1

component: unfiledattributes
keywords: → ie6 ie7 ie8
priority: undecidedlow
status: newopen

I agree that seems wrong. Do you have a test case, just for completeness?

Changed July 10, 2012 02:02PM UTC by comment:2

$(new ActiveXObject('msxml2.domdocument').createElement('test')).attr('test', 1)

throws "Type mismatch" exception in IE.

Changed August 24, 2012 01:52AM UTC by dmethvin comment:3

resolution: → invalid
status: openclosed

Looking at this further, the code only uses nodeHook on non-XML documents. The example you give would apply to cross-document/cross-frame access, which basically never works in oldIE anyway.

Changed August 24, 2012 03:18PM UTC by comment:4

I don't know why you close bug. jquery 1.8 still have it.

Problem not with IE or not IE -you create HTML attribute and set it non XML element(in case I work with xml).

If you want to create attribute use "elem.ownerDocument" to get correct one-simple "document" valid only HTML context.

So, it's logical error not directly related to my sample or IE per se.


Changed August 24, 2012 03:20PM UTC by dmethvin comment:5

Do you have a test case from the API level where it would occur? It didn't look to me like nodeHook was used anywhere but oldIE.

Changed August 27, 2012 12:21PM UTC by comment:6

We're using Windows XP through company and top version available on XP is IE8.

That's real problem,and since you declare IE6+ compatibility,why it's not a bug anymore?

Changed August 27, 2012 01:13PM UTC by dmethvin comment:7

resolution: invalid
status: closedreopened

**Do you have a test case from the API level where it would occur?** I couldn't think of one and that example above is contrived.

Changed August 27, 2012 01:14PM UTC by dmethvin comment:8

owner: →
status: reopenedpending

Reopened pending your test case.

Changed August 27, 2012 04:18PM UTC by comment:9

status: pendingnew

Talking sincerely,I can't understand what you mean by "contrived" and "API level" test case.Some example maybe?

Handling xml attributes is broken in current release- that's all I can say.

I can't set xml attribute on XML element using JQuery for IE browser.

I wouldn't call my example "contrived", it's not complete implementation-OK, but it showcase the problem. I create xml element and set attribute using JQuery API:

$(element).attr("someAttr", value).

JQuery create HTML attribute:

ret = document.createAttribute( name );

and try to set it on XML element passed:

elem.setAttributeNode( ret );

but "elem" is not HTML element in my case(it's XML element), so browser throws exception.

There's a simple fix for that problem-use elem.ownerDocument to create attribute:

ret = elem.ownerDocument.createAttribute( name );

problem solved!

You always will create attribute in correct document context,HTML or XML accordingly.


Changed August 27, 2012 04:24PM UTC by comment:10

If you want cross browser test:

$((window.ActiveXObject ? new ActiveXObject("msxml2.domdocument") : document.implementation.createDocument("", "", null)).createElement('test')).attr('test', 1)

but it throws exception only in IE.

Changed August 27, 2012 04:53PM UTC by dmethvin comment:11

status: newpending

Sorry, I am not trying to be difficult. I understand that the code change is small. I am trying to determine how this could be encountered in real code. How did you encounter the problem originally? As I mentioned, I can see this error occurring if a parent window tried to manipulate elements in an iframe in the same domain, but that is generally going to fail in oldIE because of other limitations in those browsers.

Changed August 28, 2012 06:49AM UTC by comment:12

status: pendingnew

Problem encountered lays not in HTML domain at all,it has pure XML context.

I create XML document and fill it with elements which will be sent to server after some manipulations through ajax post. I use XML DOM not HTML. Yes, problem you mention occurs by the same reason- different document contexts.

But in my case I simply construct XML document using JQuery API.

One time JQuery has very solid XML support and I like it. I can use same API for HTML and XML construction(they have very similar nature anyway). Now some glitches appears, all forget XML and focus on HTML. But XML not going away any time soon IMHO,until we not invent some kind of transformation technique a'la XSL pure and elegant(by the way XSL is XML), I mean JSON2JSON,same as XSL=XML2*. Most javascript libraries using JSON2HTML templating,but how about JSON2JSON,JSON2TEXT and alike? Many legacy projects using XML for the reason.

Query language is base for transformation, but it's only beginning. But we don't have even that starting point.

Changed September 08, 2012 05:14PM UTC by mikesherov comment:13

status: newpending

Make a test case on or that clearly shows this problem occurring so we can investigate it properly. Thanks!

Changed September 11, 2012 06:44AM UTC by comment:14

status: pendingnew try it on IE<=7 .

Changed September 14, 2012 01:18AM UTC by dmethvin comment:15

milestone: None1.9
status: newopen

Changed October 15, 2012 06:44PM UTC by gibson042 comment:16

owner: sa.cesare@gmail.comsaiwong
status: openassigned

Changed October 15, 2012 06:46PM UTC by saiwong comment:17

Changed October 20, 2012 07:30PM UTC by Sai Wong comment:18

resolution: → fixed
status: assignedclosed

Fix #12048. Set attributes for XML fragments. Close gh-965.

Changeset: 2b0e720406c42a4065010ba94e7adb7170ba74c3