How can I check if an element with a specific ID already exists in my DOM inside an Angular directive? By using angular.element()
an element is created if one does not exist, for example angular.element('someID')
will return an element whether one already exist or not.
What I am doing now as a workaround is using the .html()
jqLite function like this:
if(angular.element('#someElementID').html()) {
console.log('only fires if element already exists');
}
Is there a better way to do this? I would like to avoid including the whole jQuery just for this.
angular.element()
returns a jQuery object and not an array: docs.angularjs.org/api/ng/function/angular.element – Pocked