javascript - In firefox browser of mac osx Document.activeelement returns body instead of button element on click of button -


on javascript using document.activeelement active element button click giving me body instead of button in firefox browser of mac osx yosemite. in windows works fine.

can 1 please on how active element button .

sample code

    <!doctype html>     <html>     <head>     <script type="text/javascript">     function mainelement(){     activeelement();}     function activeelement()     {     var obj;      obj=(window.event)?((event.target)?event.target:(event.srcelement)?event.srcelement:null):document.activeelement;     alert(obj); // returns body element     }      </script>     </head>     <body>     <button onclick="mainelement()"></button>     </body>     </html> 

thanks.

change html as:

<button onclick="mainelement(event)">button</button> 

and javascript as:

function mainelement(event) {     activeelement(event); } function activeelement(event) {      event = event || window.event     alert (event.target); //the button htmlelement     alert (event.target.tagname); //button } 

some notes:

  • in ie, event object accessed through explicit object window.event.
  • in firefox, event object accessed passing event parameter event handler function in question.

Comments

Popular posts from this blog

searchKeyword not working in AngularJS filter -

sequelize.js - Sequelize: sort by enum cases -

user interface - how to replace an ongoing process of image capture from another process call over the same ImageLabel in python's GUI TKinter -