This custom function can enhance the capabilities of angular.element:
angular.element.prototype.customFunction = function customFunction(selector)
{
if( selector && selector.length )
{
var startChar = selector.substring(0, 1);
switch(startChar)
{
case '.':
return this.hasClass(selector.substring(1, selector.length)) ? this : (this.parent().length ? this.parent().customFunction(selector) : this.parent());
break;
case '#':
return selector.substring(1, selector.length) == this[0].id ? this : (this.parent().length ? this.parent().customFunction(selector) : this.parent());
break;
default: //tagname
return (this[0].tagName && selector.toLowerCase() == this[0].tagName.toLowerCase()) ? this : (this.parent().length ? this.parent().customFunction(selector) : this.parent());
break;
}
}
else
{
return this.parent();
}
}