www.insideDHTML.com
Inside Dynamic HTML | Fun and Games | The 10K Demo | XML Online | CSS Online | Resources
Write Once! | DHTML Toolkits | Inside Techniques | Inside Scriptlets

Inside Techniques/

  Introduction
moveo FunctionIE4
fadeo FunctionIE4
bubblo FunctionIE4
typeo FunctionIE4
switcho FunctionIE4
scrollo FunctionIE3,IE4,NS3,NS4
isie4 FunctionIE4
profileo FunctionIE4
Anchor FunctionIE4
Path FunctionsIE4

styleo FunctionsIE4

Download Library


 

styleo() Function

Styleo allows you to quickly change the properties in the global stylesheet. When you define a global stylesheet, it follows the form of:

<style type="text/css">
.selectorText    {CSS-Property: Value}
.myClass          {color: red}
</style>

Once you defined your stylesheet, there are two ways you can use the styleo() function. The first is to change the value of a CSS-Property, and the other is to retrieve the Value of a CSS-Property.  To change the value of a CSS-Property, you call:

styleo(".selectorText","CSS-Property", "New Value");

To retrieve the value of a CSS-Property, you call the same function but omit the new value. For example:

abc = styleo(".selectorText", "CSS-Property)

Whenever the global stylesheet is modified through script, the document needs to be rerendered. This causes the scrollbars to be repositioned at the top of the document.

styleo Function

function styleo(sel, style, val){
        for (i=0; i < document.styleSheets.length; i++)   {
                thisSheet = document.styleSheets[i];
                for (j=0; j < thisSheet.rules.length; j++) {
                        thisRule = thisSheet.rules[j];
                        if (thisRule.selectorText == sel) {
                                rule = thisRule;
                                break;
                        }
                }
        }

        
        if (rule == null) return;      
        style = MakeUpper(style);
        
        theStyle = rule.style.cssText + ";";
        p = theStyle.indexOf(style);
        s = theStyle.indexOf(";", p);
        beforeRule = theStyle.substring(0, p);
        afterRule = theStyle.substring(s+1, theStyle.length);

        if (val == null) {
                c = theStyle.indexOf(":", p);
                theRule = theStyle.substring(c+2, s);
                return theRule;
        }

        newRule = style + ": " + val + ";";
        rule.style.cssText = beforeRule + newRule + afterRule;
}

function MakeUpper(x) {
        lower = new Array ("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z");
        upper = new Array ("A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z");
        newStr = "";

        for (i=0; i < x.length; i++) {
                for (j=0; j < 26; j++) {                       
                        if (x.charAt(i) == lower[j]) {
                                newStr = newStr + upper[j];
                        }
                        if (x.charAt(i) == upper[j]) {
                                newStr = newStr + upper[j];
                        }
                }
                if (x.charAt(i) == "-") newStr = newStr + "-";
                if (x.charAt(i) == " ") newStr = newStr + " ";
        }
        return newStr;
}