Why Style.left does not work in Firefox, chrome and safari ?

Author posted by Jitendra on Posted on under category Categories HTML and tagged as Tags , with 3 Comments on Why Style.left does not work in Firefox, chrome and safari ?

During working on one of my project, i found that style.left does not work with Mozilla, chrome and safari but nicely works on internet explorer.

The code was :

var docStyle = document.getElementById("divAddPartnerAndProjectEntities").style;
docStyle.top = e.clientY;
docStyle.left = e.clientX-5;
docStyle .style.display = "";
And the simple solution is, append “px” at the end to work with other browsers.
and final code is:
var docStyle = document.getElementById("divAddPartnerAndProjectEntities").style;
docStyle.top = e.clientY+"px";
docStyle.left = e.clientX-5+"px";
docStyle .style.display = "";

Very Simple right ? 🙂

Related posts

  • Shraddha

    accurate solution!!!!!!!

  • Poorna_meenakshi

    super.. 🙂

  • Sanjeev Kumar

    Thanks a lot…… Very elegant solution. Thank you for sharing this.