Currently I am doing something like this:
function newFont(newSizeA, newSizeB) {
var elem = document.getElementById('style-1');
if (typeof(elem) != 'undefined' && elem != null) {
removeChildNodes(elem); // function that removes child
nodesremoveNode(elem);
}
var styleText = ".a { font-size:" + newSizeA + "px; } .b { font-size:" + newSizeB + "px; }";
var x = document.createElement('style');
x.setAttribute("type", "text/css");
x.setAttribute("id", "style-1");
if (x.styleSheet) { // for IE
x.styleSheet.cssText = styleText;
}
else { // others
var textnode = document.createTextNode(styleText);
x.appendChild(textnode);
}
}
The point of it is that there is a loop happening and another function is measuring the size of a menu to make sure it fits in a spot when someone is changing the font size.
I am wondering, is there a better way to create and manipulate elements? I need to change padding and font size but right now as you can see I'm just removing it entirely and recreating it.