View Full Version : Element and 'the selector should not contain an id'

23 Feb 2007, 7:35 PM
Looking at the documentation for an element, I'm baffled by the comment for domQueries:

the selector should not contain an id. (Yet ids are what Jack's blog is demonstrating the test were run with.)

So what should I do if I need all classes within a certain HTML element marked with a unique ID?

#wrap .ui-pnl, #wrap .ui-slc


23 Feb 2007, 10:49 PM
The beginning of the description for Element.select says:

Creates a CompositeElement for child nodes
Therefore, you would get your parent first, then query for child nodes. For example:

There would never be any point in actually passing an id to the selector function since by definition the id is unique and cannot return multiple matches.

24 Feb 2007, 6:39 AM
The selector can contain an id, but it just slows down the query when executed on an element.

The difference between Element.select and Ext.select is Element.select automatically prepends an id selector for that element. e.g.

Ext.select('#foo .bar'); is execued exactly how it looks '#foo .bar'.

But, when executed within the scope of an element

var el = Ext.get('foo');

the actual selector executed is automatically '#foo .bar'. So if you include a sub id:

el.select('#other .bar')

then the query becomes '#foo #other .bar' which is a scoped id selector and is much slower than a normal id selector. So it's better to just use:

Ext.select('#other .bar') where it will be executed without the extra scoping.

Hopefully all this makes some sense. :)

24 Feb 2007, 6:57 AM
Got it...martin