Why not use the event's target
:
$(document).ready(function () {
$(document).click(function (e) {
alert(e.target.id);
});
});
JSFiddle example found here.
سؤال
I need to get the current active element on my web page I used
$(document.activeElement)[0].id
This is working fine in Internet Explorer, but in Firefox it always return empty string ""
Please tell me how can I get active element's id
in Firefox?
Here is a simple scenario
I have 2 div with ID div1 and div2 respectively, now when user click on them I should get it's ID
Here is my markup
المحلول
Why not use the event's target
:
$(document).ready(function () {
$(document).click(function (e) {
alert(e.target.id);
});
});
JSFiddle example found here.
نصائح أخرى
The problem is not in the code. But, the fact that, div
cannot be active.
In fact, elements, which a user cannot interact, cannot be active.
For such elements, the id of the <body>
will be returned.