That would go like this * {margin:0; padding:0;} in CSS.
A:
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
2010-02-06 10:35:53
This would only set the styles on the body, the question is to set the styles on everything - *
meouw
2010-02-06 10:37:38
Actually I want to change the cursor type for the whole document (not only within the body).
Frank Furd
2010-02-06 10:39:58
+5
A:
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
2010-02-06 10:40:49
see 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
2010-02-06 14:30:56