javascript get style and increment
问题 I'm trying to make a slider that changes the margin-left attribute in the external css onclick. So I need to get the attribute and then set the new attribute. here is my code: <style> #divName { margin-left:20px; } </style> <script language="javascript" type="text/javascript"> var x = document.getElementById(divName); if (x.currentStyle) { var y = x.currentStyle[marginLeft]; } else (window.getComputedStyle) { var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(marginLeft);