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
$docuemnt.activeElement for that but it was always
undefined. But when I used
$document.activeElement I am getting the currently active element.
$document.activeElement is the right way to access the currently active element? Or am doing something wrong?
Practice As Follows
$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
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