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

Get articles everyday as a email directly to your inbox:
Click to publicize, if you like this article :

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 ? :)

Possibly Related posts:

  1. Style File upload control in ASP / HTML
  2. Get Mouse Position in JavaScript for all browsers
  3. Create Pure CSS based Menu – Step by Step Tutorial
  4. Highlight Current field using JQuery
You can leave a response, or trackback from your own site.
  • Poorna_meenakshi

    super.. :)

  • Shraddha

    accurate solution!!!!!!!