Skip to content

Instantly share code, notes, and snippets.

@connor4312
Last active August 29, 2015 14:06
Show Gist options
  • Save connor4312/ec15140e972dc27ae465 to your computer and use it in GitHub Desktop.
Save connor4312/ec15140e972dc27ae465 to your computer and use it in GitHub Desktop.
Find an angular element by in a scope.
/**
* Simple jquery extension to find all elements in a certain Angular scope.
* Usage:
*
* var myElement = $.inScope('.item', $scope);
*
* @param {string} selector
* @param {Angular.Scope} $scope
* @returns {jQuery}
*/
jQuery.inScope = function (selector, $scope) {
var out = [];
jQuery(selector).each(function () {
var $el = jQuery(this);
if ($el.scope() === $scope) {
out.push($el);
}
});
return jQuery(out);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment