user1855009
user1855009

Reputation: 971

Possible to retrieve only a portion of xml data loaded with ajax?

I have my application loading and parsing my xml data with ajax, but I only want to return a specific number of values - starting with the first.

I feel like I should be able to specify what I want here: $(xml).find("person").each(function()

I almost got what I needed by including .first(): $(xml).find("person").first().each(function()

But that only loads the first instance, whereas I need the first ten. Is it possible to do this?

Upvotes: 0

Views: 126

Answers (1)

djf
djf

Reputation: 6757

You can use the slice function to reduce the set of matched elements to a subset specified by a range of indices. Then apply a function to each element as usual:

$(xml).find('person').slice(0,9).each(function () ... )

Upvotes: 1

Related Questions