0

Can anyone recommend the best way to do the following?

I need a loop that will loop through the first two xml items and do something with the contents, then a second loop that will loop through items 3 onwards and do something different? How can I specify this?

Thanks for your help

Paul

3
  • Got any code to show us? A place to start? Commented Sep 16, 2011 at 16:19
  • What is the problem? Don't you know how to write loops in JavaScript? Do you even need a loop? Why not access these elements directly? Commented Sep 16, 2011 at 16:20
  • No sorry - just an xml feed parsed by jquery into a variable called XML, each story is within an item node, just dont know how to approach a loop to parse it all.. Commented Sep 16, 2011 at 16:22

1 Answer 1

1

Just loop through the items as you would normall (using $.parseXML() and $.each()), but check for the index of the item you're looking at and perform the different actions there.

For example: http://jsfiddle.net/lukemartin/RsXw9/

http://api.jquery.com/jQuery.parseXML/

http://api.jquery.com/each/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.