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 ? 🙂

Posted

in

by


Related Posts

Comments

3 responses to “Why Style.left does not work in Firefox, chrome and safari ?”

  1. Shraddha Avatar
    Shraddha

    accurate solution!!!!!!!

  2. Poorna_meenakshi Avatar
    Poorna_meenakshi

    super.. 🙂

  3. Sanjeev Kumar Avatar
    Sanjeev Kumar

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

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Discover more from Jitendra Zaa

Subscribe now to keep reading and get access to the full archive.

Continue Reading