javascript - My extension of jQuery's next is acting unexpectedly -


i extending jquery method find given selector using given function way traverse through this's siblings.

the reason i'm doing because jquery's next() doesn't keep traversing object's siblings, need.

(function ($) {   $.fn.extend({     findsibling: function (selector, fn) {       var $this = $(this),           $sibling = fn($this);       if ($sibling.length === 0){         console.log("no " + selector + " found.");       } else if($sibling.is(selector)) {         console.log(selector + " has been found!");         return $sibling;       } else {         $sibling.findsibling(selector, fn);       }     }   }); }(jquery));  $next = $this.findsibling('.line', function (object) {   return object.next(); }); 

even when function finds i'm looking for, $next remains undefined.

thanks help.

       $sibling.findsibling(selector, fn); 

should be

       return $sibling.findsibling(selector, fn); 

Comments

Popular posts from this blog

c++ - Function signature as a function template parameter -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -

How to call a javascript function after the page loads with a chrome extension? -