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
Post a Comment