Sola
Sola

Reputation: 1522

Good way to read through XML node via jQuery? with limited loop!

Currently the feed xml will return 20 items (child), and each time I only want to display 10 item in single page. The .each function of jQuery will loop whole document right? but I want make it only loop 10 items? Do I need to use the ':eq()'?

Note: I need use this for mobile device environment.

<channel>​
 <title>​Property​</title>​
 <link>​</link>​
 <lastbuilddate>​Wed, 13 Oct 2010 23:50:51 GMT​</lastbuilddate>​
 <generator>​FeedCreator 1.8.0-dev ([email protected])​</generator>​
 <atom:link href=​"sample.com" rel=​"self" type=​"application/​rss+xml">​</atom:link>​
 <item>​
  <title>​sample title​</title>​
  <description>​
    #cdata-section
  </description>​
  <pubdate>Wed, 08 Dec 2010 23:04:25 GMT</pubdate>
 </item>​
 <item>... ... </item>
 <item>... ...</item>
 <item>... ... repeat 20 times </item>
<channel>​

Upvotes: 0

Views: 328

Answers (1)

kobe
kobe

Reputation: 15835

Make a count variable ,

as soon as you reach count=10 break the loop by doing a return false

doing a return ///it should break the loop

jsFiddle example here

http://jsfiddle.net/SxEVT/

Upvotes: 1

Related Questions