Tip: Click lines to highlight, hold ctrl/cmd to multi-select

http://codedumper.com/ejuno (17-Feb @ 03:11)

Syntax Highlighted Code

  1. $.each({
  2.     prevOf: "previousSibling",
  3.     nextOf: "nextSibling"
  4. }, function( method, traversal ) {
  5.     $.fn[ method ] = function( selector ) {
  6.         return this.pushStack( this.map(function() {
  7.             var ret = this[ traversal ];
  8.             while ( ret && !$( ret ).is( selector ) ) {
  9.                 ret = ret[ traversal ];
  10.             }
  11.             return ret;
  12.         }) );
  13.     };
  14. });
  15.  

Plain Code

$.each({
    prevOf: "previousSibling",
    nextOf: "nextSibling"
}, function( method, traversal ) {
    $.fn[ method ] = function( selector ) {
        return this.pushStack( this.map(function() {
            var ret = this[ traversal ];
            while ( ret && !$( ret ).is( selector ) ) {
                ret = ret[ traversal ];
            }
            return ret;
        }) );
    };
});

Codedump Run

Permalink: http://codedumper.com/ejuno