Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1069343
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T20:24:37+00:00 2026-05-16T20:24:37+00:00

New to jQuery, I have a script that returns data from an XML file.

  • 0

New to jQuery, I have a script that returns data from an XML file. What I need is the index number of the element returned. I know I can retreve a single element with this

name = $("sitelist:eq(1)",data).text();

but in my script I need to know each element position for the displayed data.
something like position = $(data,eq).value .Can anyone help please .

$(document).ready(function () {

    $.ajax({
        type: "GET",
        url: "sites.xml",
        dataType: "xml",
        success: displayXml
    });

    function displayXml(data) {
        $(data).find("course").each(function () {
            var name = $(this).find("sitelist").text();
            var line1 = $(this).find("address1").text();
        });
    }
}); // doc ready
  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T20:24:38+00:00Added an answer on May 16, 2026 at 8:24 pm

    I’m not sure which node you need the index for, but if it is the course that you’re iterating over with .each() you can get the index of each iteration from .each()

     $(data).find("course").each(function( idx ) {
          alert( idx ); // will alert the index of the current "course"
    
          var name = $(this).find("sitelist").text();
          var line1 = $(this).find("address1").text();
     });
    

    If there’s some other situation, you could try using the .index() method to get the index of the node from among its siblings. It requires jQuery 1.4 or later.

    As in:

    var $sitelist = $(this).find("sitelist");
    var index = $sitelist.index();
    var name = $sitelist.text();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jQuery script that polls my server for new data, but it
I want to retrieve data from restful webservice that returns xml. I'm using phonegap.
I have application that brings response via Ajax and creates 5-20 new jQuery click
I'm new to jQuery and I want to have a input box from a
I have two jQuery autocomplete textboxes on a mvc web page. One that returns
I am using a jQuery Ajax control from this site http://abeautifulsite.net/2008/03/jquery-file-tree/ I have it
EDITED I'm trying to use jquery/ajax to display data returned from a django method.
I have a jQuery autocomplete fild which gets existing data from my MVC action.
i'm new to jquery .I have problem in the following code .I saved it
I'm new to jQuery and have noticed someone go: var $this = $(this); Why

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.