RRRSystems Posted February 27, 2011 Share Posted February 27, 2011 Hello,I am trying to change the margin-left from 12px to 0px via the function setMarginLeft().I would just like to see it work before I actually put it to any good use.I am testing using IE8, but would like to finally end up with something thatwill work for most common browsers.I have been looking at many suggestions, but it just doesnt seem to do anything.Any thougnts?Thanks,RaneyA Div declared in the .html -------------------------------<DIV CLASS = "Page Area" ID = "Body"> Body Area<BR> Body Area<BR> Body Area<BR> Body Area<BR></DIV>The following are defined in the Application.css file:loaded in the <HEAD> of the .html<LINK REL = "StyleSheet" HREF = "Style/Application.css">----------------------------------------------------------.Page{ width: 980px;}.Area{ clear: both; float: none; position: absolute; overflow: hidden;}}#Body{ margin-left: 12px;} The following function is declared in the Application.js file:loaded in the <HEAD> of the .html<script SRC = "Script/Application.js"></SCRIPT>and called from the <BODY> of the .html<script>setMarginLeft()</SCRIPT> -----------------------------------------------------------function setMarginLeft() { element = document.getElementById("Body"); element.style.marginLeft = "0px";} Link to comment Share on other sites More sharing options...
birbal Posted February 27, 2011 Share Posted February 27, 2011 i think it will beelement.style.margin-left = "0px";instead of element.style.marginLeft = "0px"; Link to comment Share on other sites More sharing options...
Ingolme Posted February 27, 2011 Share Posted February 27, 2011 Answering the question: Just be sure that setMarginLeft() is called after the #Body element. If it is before the element then it won't work because the element hasn't loaded yet. i think it will beelement.style.margin-left = "0px";instead of element.style.marginLeft = "0px";No, that's incorrect.That's performing a subtraction:element.style.margin - left = "0px" would throw an error because an operation is an invalid value for the left of the assignment operator and the left variable is undefined.The proper way to deal with CSS properties that contain hyphens is to remove the hyphens and capitalize the character that follows it. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.