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 7078591
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:34:00+00:00 2026-05-28T06:34:00+00:00

it appears that $(html).find(‘*’).index(‘#theID’); yields -1 whereas $(html).find(‘*’).each(function(ind){if(this.id==’theID’) alert(‘found! @’+ind) } ); does work

  • 0

it appears that

$(html).find('*').index('#theID');

yields -1 whereas

$(html).find('*').each(function(ind){if(this.id=='theID') alert('found! @'+ind) } );

does work (alerting 229)

I am using Windows 7 with IE 8 and jquery 1.6.1

My question is, why doesn’t the first one work? Thanks.

  • 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-05-28T06:34:01+00:00Added an answer on May 28, 2026 at 6:34 am

    Look at the jQuery documentation for index. The API for a string argument is as follows (italic emphasis added):

    selector A selector representing a jQuery collection in which to look
    for an element
    .

    …

    If a selector string is passed as an argument, .index() returns an integer indicating the position of the original element relative to the elements matched by the selector. If the element is not found, .index() will return -1.

    To do what you are trying to do requires you to pass an element (or jQuery object) as the argument, not a string. Therefore, something like this should do what you want:

    $(html).find("*").index($("#theID", html));

    Edit (see comments)

    Since html is a string, creating 2 different jQuery objects from that string is going to cause problems. To solve that, you can pass it into jQuery once:

    var $html = $(html);
    $html.find("*").index($html.find("#theID"));
    

    The documentation for this form of index states the following:

    element The DOM element or first element within the jQuery object to
    look for.

    …

    If .index() is called on a collection of elements and a DOM element or
    jQuery object is passed in, .index() returns an integer indicating the
    position of the passed element relative to the original collection.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

It appears that calling Html.RenderAction in Asp.Net MVC2 apps can alter the mime type
It appears that each app has access to its own config settings, which could
I'm trying to find all occurrences of items in HTML page that are in
I have an application that fires several processes. Each process loads an HTML file
edit It appears that this is just a case of the sample code being
Appears that WAS does not support the integration binding. I've tried setting it up
It appears that using perldoc perl gives the list of, e.g. perlre, perlvar, etc.
It appears that in PHP objects are passed by reference. Even assignment operators do
It appears that Directory.GetFiles() in C# modifies the Last access date of a file.
It appears that I can escape command line arguments using single or double quotes:

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.