Skip to main content

Bug Tracker

Side navigation

#13552 closed bug (notabug)

Opened March 02, 2013 08:37AM UTC

Closed March 02, 2013 01:34PM UTC

Last modified March 02, 2013 06:44PM UTC

Custom Pseudo Selector fails if name starts with "eq"

Reported by: Owned by:
Priority: undecided Milestone: None
Component: selector Version: 1.9.1
Keywords: Cc:
Blocked by: Blocking:

See this jsfiddle.

If you create a pseudo selector and the name of it starts with "eq" then it does not behave as expected. Every element of the DOM gets passed to the selector function. eg.

$.expr[':'].eqXYZ = $.expr.createPseudo(...)

simply changing the name to "esXYZ", then everything works as expected. Seems like the tokenizer bug?

Attachments (0)
Change History (5)

Changed March 02, 2013 01:34PM UTC by gibson042 comment:1

component: unfiledselector
resolution: → notabug
status: newclosed

We make no guarantees about ''which'' elements get passed to a custom pseudo function, only that we will honor its return value for excluding elements from the final matched set:

But for the record, there is currently a performance penalty if your custom pseudos is prefixed with a standard positional pseudo (even|odd|eq|gt|lt|nth|first|last), the effects of which you are observing here.

Changed March 02, 2013 03:24PM UTC by comment:2

Please make a note of this in the documentation here:

Changed March 02, 2013 04:21PM UTC by gibson042 comment:3

The return result from this function should be a boolean (true if the element matches the selector, false if not).

What would you have us change?

Changed March 02, 2013 05:13PM UTC by comment:4

I'd like to see the documentation to include:

"Note: Custom pseudo functions prefixed with standard position pseudo (even|odd|eq|gt|lt|nth|first|last) may incur a performance penalty. In general, there are no guarantees on which elements are passed to the custom pseudo function (ie. elements passed to function may not match the given selector)."

Can you explain why this is the case? Is it an optimization in jQuery or just on oversight?

Changed March 02, 2013 06:44PM UTC by gibson042 comment:5

It is axiomatic that elements passed to the function may not match... the ''purpose'' of the function is to help find out.

As for the reason why custom pseudos prefixed with a positional selector might hurt performance more than those that aren't: positional selectors need special processing, and we check for their presence with a regular expression before tokenization to skip it if possible (or at least start with a small seed set for non-positional matching). Anything that ''looks'' positional doesn't get the benefits.

Honestly, I'd recommend using the .filter( fn )method instead of defining a custom pseudo, if that would work for your purposes.