0

jsFiddle URL : http://jsfiddle.net/rcrathore/Y8DpM/

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".

Is there a way to fix this on IE8?

Ritesh
  • 7,472
  • 2
  • 39
  • 43

1 Answers1

1

The code works in all browsers if I replace appendTo line

$(newNode).appendTo($xml.find("node2"));

by :

$xml.find("node2").get(0).appendChild(newNode);

Edit

As per bugs.jquery.com (9602), this issue will be fixed in 1.6.2.

Ritesh
  • 7,472
  • 2
  • 39
  • 43