Ticket #9602 (closed bug: duplicate)
Exception when adding a new node in XML.
| Reported by: | rcrathore | Owned by: | rcrathore |
|---|---|---|---|
| Priority: | low | Milestone: | 1.next |
| Component: | manipulation | Version: | 1.6.1 |
| Keywords: | Cc: | ||
| Blocking: | Blocked by: |
Description
jsFiddle URL : http://jsfiddle.net/rcrathore/Y8DpM/[1]
I am trying to add a new node in XML using jQuery. Following code works fine in Firefox, Safari and Chrome but giving error in IE8:
<div id="result"> </div>
<div id="result2"> </div>
<script type="text/javascript"> <!--
var xml = "<root><node1><node2>TEXT1</node2></node1></root>" ; var $xml = $($.parseXML(xml)) ;
var newData = "<node3>234</node3>" ; var $newData = $($.parseXML(newData)); var newNode = null;
if (typeof document.importNode == 'function') {
newNode = document.importNode($newData.find('node3').get(0),true);
} else {
newNode = $newData.find('node3').get(0)
}
try {
$(newNode).appendTo($xml.find("node2")); /* expected TEXT1234*/ $("div#result").html($xml.text());
/* expected 234*/ $("div#result2").html($xml.find("root > node1 > node2 > node3").text());
} catch (e) {
alert(e) ; $("div#result").html("Error: " + e.description);
}
--> </script>
The error description on IE8 is "Wrong number of arguments or invalid property assignment".
Change History
comment:2 Changed 2 years ago by Isaac
Related?
//Crash in IE
var $xml = $('<xml />').append($('<root />').append('<child />'));
//Works in IE
var $xml = $('<exml />').append($('<root />').append('<child />'));
comment:3 Changed 2 years ago by timmywil
- Owner set to rcrathore
- Priority changed from undecided to low
- Status changed from new to pending
- Component changed from unfiled to manipulation
Thanks for taking the time to contribute to the jQuery project! Please provide a reduced test case on http://jsfiddle.net that reproduces the issue experienced to help us assess your ticket.
Additionally, test against the jQuery (edge) version to ensure the issue still exists.
comment:4 Changed 2 years ago by rcrathore
- Status changed from pending to new
Isaac, timmywil:
- Not sure if Isaac's example is related.
- Not sure what can be reduced in my test case. I think it is already very compact. A root element has node2 and node2 and I am inserting a new node (node3) under node2.
- I will test it with jQuery (edge) version and update this case.
comment:5 Changed 2 years ago by kabel
Duplicate of #9370. Fixed at 1d1cb582c0f744afaa51a63d374b9ffe0f58d1db
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

The code works in all browsers if I replace appendTo line
$(newNode).appendTo($xml.find("node2"));by :
$xml.find("node2").get(0).appendChild(newNode) ;