Jquery and XML - How to add the value of nodes

Posted by Matias on Stack Overflow See other posts from Stack Overflow or by Matias
Published on 2010-03-30T14:07:23Z Indexed on 2010/03/30 14:23 UTC
Read the original article Hit count: 573

Filed under:
|

Hi Experts,

This may be a simple question though can´t figure out how to do it.

I am parsing an XML with Jquery Ajax. It contains dates and rates

The XML looks something like

<rate>
 <date>Today</date>
 <price>66</price>
</rate> 
<rate>
 <date>Tomorrow</date>
 <price>99</price>
</rate> 

I simply want to figure out how to calculate the total price of both days Today and Tomorrow. Thought that by using Javascript Number it will simply return the total value of the nodes..

$(xml).find("rate").each(function()
{
   $(this).find("price").each(function()
   {
   $("#TOTALPRICE").append(Number($(this).text()));
   }

}
//output is: 6699 

However, it´s just concatenating the values both not adding them.

//output is: 6699 

I greatly appreciate your help !!

Thanks

© Stack Overflow or respective owner

Related posts about jquery-ajax

Related posts about Xml