AngularJS closest() function

;(function () { var app = angular.module('App', []); app.run(function () { let jqLite = angular.element; jqLite.prototype.closest = function (className) { return (function closest (element, className) { if (element[0].nodeName === 'HTML') { return null; } else if (element.hasClass(className)) { return element; } else { return closest(element.parent(), className); } })(this, className); }; }); })();
Similar to the closest() function of jQuery.

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.