#267 closed bug (fixed)
query for id in context ignores context
Reported by: | joern | Owned by: | |
---|---|---|---|
Priority: | major | Milestone: | 1.1a |
Component: | core | Version: | 1.1a |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
From Christof Donat:
JQuery could check if context.getElementById exists and if it doesn't walk the elements in the context and return the first Element it finds that has the given ID:
if( context.getElementsById ) elems = [context.getElementsById(id)]; else { var f = function(i,c) { if( c.id == i ) return [c]; for( ch in c.childNodes ) { if( ch.nodeType != 1 ) continue; var r = f(i.ch); if( r.length > 0 ) return r; } return []; } elems = f(id,context); }
That means that for browsers with a good implementation of getElementById() $('#myid',context) is much slower than $('#myid'), but it returns the expected result. At least that should not be slower than $('.myclass',context).
Change History (5)
comment:1 Changed 16 years ago by
comment:2 Changed 16 years ago by
IDs don't need a context but in case there is a context, the Element with the ID should only be returned in case it is in the context.
comment:3 Changed 16 years ago by
It is useful to accomplish other tasks too, to select elements inside iframes as an example. It is currently impossible to select an element inside an iframe by id from the iframe parent document. If you give as context the iframe document, it is simply ignored and the parent document is used in place of it.
comment:4 Changed 16 years ago by
Milestone: | → 1.1 |
---|---|
Priority: | minor → major |
Version: | → 1.1 |
Is this really necessary? Spec says ids are to be unique and therefore do not need context.