Adding XML nodes to an XMLDocument with jQuery 1.5

Adding XML nodes to an XMLDocument with jQuery 1.5

Hi there, I have the following code:

  1. $(document).ready(function()
  2. {
  3. // The DOM (document object model) is constructed
  4. // We will initialize and run our plugin here
  5. var tmp = [
  6. '<person>',
  7. '<name>Richard</name>',
  8. '</person>' ].join('');
  9. var xmlDoc = $.parseXML(tmp);
  10. var personElement = $(xmlDoc).find('person');
  11. $(personElement).attr('type', 'vip');
  12. // would like to append <age>28</age> to personElement
  13. $(personElement).append('<age>28</age>');
  14. alert(xmlDoc.xml);
  15. });
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!