I have an old script for changing the font size of a website by adding a class name to the body tag, and part of its functionality is to remove the existing class before changing it to one of the other settings. The problem is there's an eval
line that removes any instance of the words "large," "medium," or "small" from other classes on the body tag which act as unique identifiers of the page, which interferes with other scripts I'm using. How can I change the eval line in the following code so that it only matches whole words?
/* Override CSS with global font size selected by user */
function changeFontSize(size) {
var oldClasses, currentClass;
/*sets key words to be eliminated*/
oldClasses = eval("/large|medium|small/ig");
/*gets the current class names*/
currentClass = document.body.className;
/*eliminates key words from string, then adds new size*/
document.body.className = currentClass.replace(oldClasses, "") + " " + size;
}