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

  • Home
  • SEARCH
  • 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 7867627
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T00:45:22+00:00 2026-06-03T00:45:22+00:00

If I have a structure like this: <body> <div data-role=page data-dom-cache=true id=foo>…</div> <div data-role=page

  • 0

If I have a structure like this:

<body>
 <div data-role="page" data-dom-cache="true" id="foo">...</div>
 <div data-role="page" data-dom-cache="true" id="bar">...</div>
 <div data-role="page" data-dom-cache="true" id="baz">...</div>
</body>

How do I get the position of bar in this series of divs? It should return 2 in this case.

I’m using this to try to get the index of the current page in jquery mobile. Right now I’m doing:

$( '#<%=@page_id%>' ).bind( 'pageshow',function(event){
    alert('current page = '+$.mobile.activePage.index())
})

But this is showing me index=1 for the 1st page, index=3 for the 2nd page and from there it increases linearly to 4,5…

  • 1 1 Answer
  • 0 Views
  • 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-06-03T00:45:23+00:00Added an answer on June 3, 2026 at 12:45 am

    Use index():

    var index = $('#bar').index();
    

    Which will return the index position of the element among its sibling elements, or you can pass a selector:

    var index = $('#bar').index(selector);
    

    Wherein jQuery will return the index position of $('#bar') among the matched elements returned by the selector passed to index.

    Note that JavaScript works with zero-based arrays; so the above (in the first) will return 1 (not 2). If you must have 2 then remember to explicitly + 1:

    var index = $('#bar').index() + 1;
    

    But, when using that index variable (perhaps with eq()) remember to adjust for that addition, otherwise things may break unexpectedly. Or, at least, work differently.

    References:

    • index().
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a folder structure like this: /some_folder /tmp /tmp/foo /tmp/foo/fu * /tmp/bar /tmp/bar/bah
I have structure like this <div id=mali_oglasi> <p class=mali_oglas> <span class=name>Predaja7</span> <span class=body>Lorem ipsum
I make a website with DOM structure like this: <body> <div><canvas id=cv></canvas> <script> ..some
I have structure like this: <div id=mali_oglasi> <?php foreach ($mgs as $key) : ?>
I have a data structure that represents C# code like this: class Namespace: string
I have a structure like this: <ul> <li>text1</li> <li>text2</li> <li>text3</li> </ul> How do I
I have a structure like this.... UITableViewController -> UITableViewCell -> UIView I need the
I have xml structure like this: <Group id=2 name=Third parentid=0 /> <Group id=6 name=Five
Currently I have a structure like this: A | +--B | +--C It's mapped
The typical Python threadpool will have a structure like this one: def run(self): while

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.