Setting CSS/Style float from javascript

If we ever try to set the float of an element through Javascript, setting the element float as below is not possible because the javascript DOM doesn’t have a definiton for float on style property.
element.style.float="left";
Solutions for this are dependent on the Browsers
  • cssFloat for Firefox, Opera, Safari & Edge
    element.style.cssFloat="left";
  • For IE
    element.style.styleFloat="left";
Not only this property, the standard things to check while writing Javascript are
  • Does DOM consists of what we are writing?
  • Are we following naming convention matching to browsers DOM
    element.style.padding="0px"; // started with small letter 
    element.style.paddingLeft="0px"; //each pronounced word is capitalized
    		
  • Do we assign values as DOM is expecting from us?
    style.width="100px" //valid 
    style.width=100; //is invalid
Scroll to Top