I am using jQuery ajax function to handle data tracking from database. The returned data in this function is like
<root>
<result city='LA' state='CA'></result>
<result city='DALLAS' state='TX'></result>
...
</root>
I’m using
var count=$(data).find("result").length();
to get count of result nodes, but it is not right.
So how to count result nodes using jQuery?
Assuming
datais an XML Node object,$(data).find("result").lengthis fine. No brackets,lengthis a property not a method. There is a method that does the same thing,size(), though there’s no real advantage to using it.(If
datawere actually a string, you’d have to parse that into an XML document first. Passing non-HTML markup to$()is the wrong thing and only works sometimes by luck.)