Adding XML nodes to an XMLDocument with jQuery 1.5
Hi there, I have the following code:
- $(document).ready(function()
- {
- // The DOM (document object model) is constructed
- // We will initialize and run our plugin here
- var tmp = [
- '<person>',
- '<name>Richard</name>',
- '</person>' ].join('');
-
- var xmlDoc = $.parseXML(tmp);
- var personElement = $(xmlDoc).find('person');
-
- $(personElement).attr('type', 'vip');
-
- // would like to append <age>28</age> to personElement
- $(personElement).append('<age>28</age>');
-
- alert(xmlDoc.xml);
- });
On line 17, I would like to be able to add a new child element to the <person> element, but every attempt I've made so far has failed... I'm able to modify any existing elements, but thus far I've not been able to add a new one. Please please please tell me there's a way to do it!