Skip to main content

Bug Tracker

Side navigation

#267 closed bug (fixed)

Opened October 10, 2006 09:31PM UTC

Closed December 20, 2006 03:23AM UTC

Last modified June 19, 2007 07:01AM UTC

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).

Attachments (0)
Change History (5)

Changed October 11, 2006 03:00AM UTC by brandon comment:1

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

Changed October 11, 2006 07:56AM UTC by Christof Don comment:2

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.

Changed October 13, 2006 03:04PM UTC by Renato comment:3

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.

Changed November 17, 2006 09:55PM UTC by john comment:4

milestone: → 1.1
priority: minormajor
version: → 1.1

Changed December 20, 2006 03:23AM UTC by brandon comment:5

resolution: → fixed
status: newclosed

Fixed in REV 731 by Dave