select by ID sometimes works, sometimes doesn't

select by ID sometimes works, sometimes doesn't

I'm pretty new at this - been using JQuery about three weeks full-time with good success. But...
 
Some of the elements in my HTML can be selected by their ID's, using the $("#some-id") syntax, and some can't (the selector returns an empty set). In the debugger (Visual Studio) at a break point in the Javascript, I copy the ID value directly out of the html into the immediate window and run something like to print out the length property of the wrapped set:
    ?$("#unfindable").length
and get zero.
 
I can do the same thing on other ID's and JQuery finds them as I would expect, and I can't see the difference between the ones that JQuery finds and the ones it doesn't: for instance, they might both be divs. These aren't form input fields - for those I use something like $(":input[id='some-id']") and it works consistently.
 
I don't do anything fancy like changing ID's at runtime - this is all simple static HTML, so I know that the element is there in the DOM and that it has the ID I'm looking for.
 
Any suggestions?
 
Thanks,
Tom Dacon