Bug Tracker

Opened 13 years ago

Last modified 12 years ago

#4101 closed feature

add public contains method — at Initial Version

Reported by: joern Owned by:
Priority: major Milestone: 1.4
Component: core Version: 1.4a1
Keywords: Cc:
Blocked by: Blocking:


Both Sizzle and jQuery UI core have their own internal contains-method. This could/should be added to the public API, maybe as a filter-variant:


To accept the most variant of arguments, a double-filter would be necessary:

// already exists in Sizzle
var contains = document.compareDocumentPosition ?  function(a, b){
	return a.compareDocumentPosition(b) & 16;
} : function(a, b){
	return a !== b && (a.contains ? a.contains(b) : true);
$.fn.contains = function(target) {
  var targets = $(target);
  return this.filter(function() {
    var container = this;
    return targets.filter(function() {
      return container.contains(this);

Probably a rather naiive implementation, but it would ensure that both each of the selected elements and each of the arguments are considered.

Change History (0)

Note: See TracTickets for help on using tickets.