Skip to main content

Bug Tracker

Side navigation

#12409 closed bug (fixed)

Opened August 27, 2012 06:29PM UTC

Closed August 27, 2012 07:45PM UTC

Last modified October 24, 2012 07:19PM UTC

Back-compat issue with custom pseudo selectors

Reported by: johnbillion Owned by:
Priority: low Milestone: 1.8.1
Component: selector Version: 1.8.0
Keywords: Cc:
Blocked by: Blocking:

The API for adding a custom psuedo selector which accepts an argument changed in jQuery 1.8. Prior to 1.8, one could do the following in order to create an :icontains(text) pseudo selector:

jQuery.expr[':'].icontains = function( obj, index, meta, stack ) {

	return (
		obj.textContent ||
		obj.innerText ||
		jQuery(obj).text() ||
	).toLowerCase().indexOf(meta[3].toLowerCase()) >= 0;


In jQuery 1.8 this triggers a TypeError as the function parameters have effectively changed and the meta parameter is now undefined.

The API for creating a custom psuedo selector which accepts an argument is completely different in 1.8 and is not back-compatible with the method used for 1.7.

In my opinion, a change like this which is not back-compatible with the previous method is classed as a bug. A plugin which adds a pseudo-selector like this now must be updated for jQuery 1.8, and if it wishes to retain support for jQuery 1.7 will have to introduce logic to determine which method to use to add the pseudo selector.

Attachments (0)
Change History (7)

Changed August 27, 2012 07:45PM UTC by timmywil comment:1

component: unfiledselector
priority: undecidedlow
resolution: → wontfix
status: newclosed

Thank you for contributing to the jQuery project!

The decision to break the API for creating custom pseudos with arguments was not taken lightly. Given the new selector compilation in Sizzle, backwards compatibility for this API would be more code and work than it's worth. We strongly recommend using the new API whenever possible because of its performance benefits and readability.

Having said that, a case-insensitve contains seems pretty common, so I've added an example implementation for this custom pseudo that will work across all versions of jQuery here:

Changed August 27, 2012 08:54PM UTC by Timmy Willison comment:2

resolution: wontfixfixed

Sizzle: provide backwards-compatibility for creating custom pseudos with arguments. Fixes #12409.

Changeset: f15eb3ce5b3e7967f04cb1a6d57542bd6f9f9262

Changed August 27, 2012 08:56PM UTC by timmywil comment:3

We gave in.

Changed August 27, 2012 08:59PM UTC by dmethvin comment:4

Hell no! We ROSE to the challenge!

Changed August 28, 2012 01:52AM UTC by dmethvin comment:5

milestone: None1.8.1

Changed August 30, 2012 02:14PM UTC by johnbillion comment:6

Nice work folks!

Changed October 24, 2012 07:19PM UTC by Tom comment:7

jQuery 1.8.2 - the backward compatible solution always returns 0 for the index, so it breaks some existing custom pseudos selectors that rely on this.

This demos the problem:

Switch between jQuery 1.8.2 and jQuery 1.7.2.