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.
Look at the jQuery documentation for
index. The API for a string argument is as follows (italic emphasis added):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
htmlis 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:The documentation for this form of
indexstates the following: