Question

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

http://pastebin.com/BCW8ECMx

Was it helpful?

Solution

Why not use the event's target:

$(document).ready(function () {
   $(document).click(function (e) {
      alert(e.target.id);
   });
});

JSFiddle example found here.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top