Bug Tracker

Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#12409 closed bug (fixed)

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.

Change History (7)

comment:1 Changed 9 years ago by timmywil

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: https://github.com/jquery/sizzle/wiki/Sizzle-Documentation#wiki-back-compat

comment:2 Changed 9 years ago by Timmy Willison

Resolution: wontfixfixed

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

Changeset: f15eb3ce5b3e7967f04cb1a6d57542bd6f9f9262

comment:3 Changed 9 years ago by timmywil

We gave in.

comment:4 Changed 9 years ago by dmethvin

Hell no! We ROSE to the challenge!

comment:5 Changed 9 years ago by dmethvin

Milestone: None1.8.1

comment:6 Changed 9 years ago by johnbillion

Nice work folks!

comment:7 Changed 9 years ago by Tom

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: http://jsfiddle.net/ttkaminski/8RdtA/ Switch between jQuery 1.8.2 and jQuery 1.7.2.

Note: See TracTickets for help on using tickets.