Anirudhan J Anirudhan J - 6 months ago 60
Javascript Question

Angularjs $document[0].activeElement instead of $document.activeElement

I am writing a placeholder directive using angularjs.

On the click handler I want to check if the element and document.activeElement are the same.

I tried to use

for that but it was always
. But when I used
I am getting the currently active element.

is the right way to access the currently active element? Or am doing something wrong?

Answer Source

No, $document is a wrapped version of document, it is wrapped using jQlite which is a tiny version of jQuery, so $document doesn't have any method called activeElement because document is inside $document, So you'll have to use




You could also create a global variable that is a wrapped version of activeElement like so.

var $activeElement = angular.element(document.activeElement);
$activeElement.attr('focused', 'yes'); // Example usage
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download