You don't need to iterate all the elements. You can demand this operation to the CSS engine of your browser. Something like that:
;(function(exports) {
var style = document.querySelector("head")
.appendChild(document.createElement("style"));
var styleSheet = document.styleSheets[document.styleSheets.length - 1];
styleSheet.insertRule("* {}", 0);
exports.universal = styleSheet.cssRules[0];
}(window));
From now, you have a window.universal
object that you can use to style all the elements. For instance:
window.universal.style.border = "1px solid red";
Of course you don't need to create at runtime the <style>
tag. You can always have that in plain HTML too.
You can test it running this snippet:
;(function(exports) {
var style = document.querySelector("head")
.appendChild(document.createElement("style"));
var styleSheet = document.styleSheets[document.styleSheets.length - 1];
styleSheet.insertRule("* {}", 0);
exports.universal = styleSheet.cssRules[0];
}(window));
console.log("universal" in window); // true
window.universal.style.border = "1px solid red";
<div>
Hello
<span>World</span>
</div>