Why does this work?
$('#findme', '<div><div id="findme">Hello</div></div>')
And this does not?
$('#findme', '<div id="findme">Hello</div>')
For some reason only when I have the enclosing div will jQuery find the div with the id of findme.
Even enclosing it in a different tag does not work.
$('#findme', '<html><div id="findme">Hello</div></html>')
In addition the following don’t work.
$('<div id="findme">Hello</div>').find('#findme')
$('<html><div id="findme">Hello</div></html>').find('#findme')
Although this works.
$('<div><div id="findme">Hello</div></div>').find('#findme')
There is something I’m not understanding about how the context works.
Thanks,
Randall
It is quite easy actually. The way you are searching is using context. So it takes the top-most node in the string, and searches through it’s children.
So imagine having the same structure in html, and parsing it:
is the same as
OR
So when you try
It obviously has no children.