Bug Tracker

Opened 16 years ago

Closed 16 years ago

Last modified 16 years ago

#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:


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 brandon

Is this really necessary? Spec says ids are to be unique and therefore do not need context.

comment:2 Changed 16 years ago by Christof Don

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 Renato

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 john

Milestone: 1.1
Priority: minormajor
Version: 1.1

comment:5 Changed 16 years ago by brandon

Resolution: fixed
Status: newclosed

Fixed in REV 731 by Dave

Note: See TracTickets for help on using tickets.