jQuery.fn.compare  function     

plugin: dom/compare
test: qunit.html

Compares the position of two nodes and returns a bitmask detailing how they are positioned relative to each other.

$('#foo').compare($('#bar')) //-> Number

You can expect it to return the same results as compareDocumentPosition. Parts of this documentation and source come from John Resig.

Demo

$.fn.compare(element) -> Number
{HTMLElement|jQuery}

an element or jQuery collection to compare against.

{Number}

A bitmap number representing how the elements are positioned from each other.

If the code looks like:

$('#foo').compare($('#bar')) //-> Number

Number is a bitmap with with the following values:

BitsNumberMeaning
0000000Elements are identical.
0000011The nodes are in different documents (or one is outside of a document).
0000102#bar precedes #foo.
0001004#foo precedes #bar.
0010008#bar contains #foo.
01000016#foo contains #bar.
© Jupiter IT - JavaScriptMVC Training and Support