That would go like this * {margin:0; padding:0;} in CSS.
Asked
Active
Viewed 1,687 times
2 Answers
7
To get the (first) stylesheet object use
document.styleSheets[0]
To access the (first) rule in the stylesheet use on of:
document.styleSheets[0].cssRules[0] // firefox
document.styleSheets[0].rules[0] // IE
You can add rules with
insertRule(rule, index) // firefox
addRule(selector, declaration, [index]) // IE
Thus, to do what you describe in firefox:
document.styleSheets[0].insertRule("*{margin:0; padding:0;}", 0)
And to do it in IE:
document.styleSheets[0].addRule("*", "margin:0; padding:0;", 0)
See also: Dom StyleSheet Object.

VoidPointer
- 17,651
- 15
- 54
- 58
-
1see http://stackoverflow.com/questions/714655/how-can-i-set-a-css-hover-on-a-dom-created-element-in-javascript/714717#714717 and http://stackoverflow.com/questions/524696/how-to-create-a-style-tag-with-javascript/524721#524721 for two different approaches on dynamically creating the stylesheet if you don't want to append to an existing one – Christoph Feb 06 '10 at 14:30
-1
If you'd like to change the padding and margin for the body element:
document.body.setAttribute('padding', '0');
document.body.setAttribute('margin', '0');

Leventix
- 3,789
- 1
- 32
- 41
-
This would only set the styles on the body, the question is to set the styles on everything - * – meouw Feb 06 '10 at 10:37
-
Actually I want to change the cursor type for the whole document (not only within the body). – Frank Furd Feb 06 '10 at 10:39