Source Code:
(back to article)
Submit
Result:
Report an issue
<!DOCTYPE html> <html> <head> <title>Title of the Document</title> </head> <body> <script> // doesn't work! document.body.style.margin = 40; console.log(document.body.style.margin); // '' (empty string, the assignment is ignored) // now add the CSS unit (px) - and it works document.body.style.margin = '40px'; alert(document.body.style.margin); // 40px alert(document.body.style.marginTop); // 40px alert(document.body.style.marginLeft); // 40px </script> </body> </html>