A little background: I was rendering some XML on the page using XSLT, but we decided to make it more interactive and so now I’m doing a jQuery.ajax call to return the XML, and I’m parsing it in JavaScript.
I’ve been able to extract particular nodes from it using code like
var qpPlanNode = $(xml).find('MyNode');
var qpPlanNum = $(qpPlanNode).children('PLANNUM').text();
And that gets the plan number into qpPlanNum. But in that XML I have something like
<xml>
<MyNode>
<PLANNUM>123</PLANNUM>
<SOURCE>
<TYPE>PreTax</TYPE>
<AMOUNT>1234</AMOUNT>
</SOURCE>
<SOURCE>
<TYPE>AfterTax</TYPE>
<AMOUNT>456</AMOUNT>
</SOURCE>
<SOURCE>
<TYPE>PreTax</TYPE>
<AMOUNT>234</AMOUNT>
</SOURCE>
</MyNode>
</xml>
I would like to extract all the SOURCE nodes that have a particular value for TYPE. I can’t find a simple jQuery selector that that will do that. In XSLT, I was doing <xsl:variable name="afterTaxSources" select="SOURCE[TYPE = 'AfterTax']"/>. What’s the JQuery equivalent?
I just stumbled on this one, which seems like it is working:
Does anybody see any reason why it wouldn’t?
Even better, I can combine multiple types using