Question

I have an XML doc that looks similar to:

<schedule techs="52" date="2009-10-06">

<tech name="Ryan (RI, MA, CT, NH)" value="1">

<time value="4">
<HONAME value="Ronald Baron"/>
<ADDRESS value="35 Liepis rd"/>
<CITY value="Canterbury"/>
<STATE value="CT"/>
<ZIP value="06331"/>
<JOBNUMBER value="33028"/>
<RESULT value="C"/>
<NOTES value=""/>
<BOARD value=""/>
</time>

<time value="9-1">
<HONAME value="Howard McFadzen"/>
<ADDRESS value="77 Crown St. Extension"/>
<CITY value="Meriden"/>
<STATE value="CT"/>
<ZIP value="06450"/>
<JOBNUMBER value="9188"/>
<RESULT value=""/>
<NOTES value="Close ticket 10097792 System keeps sending RF interference and receiver tamper, please fix"/>
<BOARD value="10-1 please"/>
</time>
</tech>
</schedule>

How do I use JavaScript/jQuery to test for empty nodes? I need to be able to check for several times and if a certain time node such as 1-5 isn't in the XML, I need to run a different function. Any ideas?

Was it helpful?

Solution

Try using the attribute equals selector

if($('time[value=1-5]').length > 0)
{
    // time 1-5 exists
    funcA();
}
else
{
    // time 1-5 doesn't exists
    funcB();
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top