SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict
    Join Date
    Mar 2005
    Posts
    314
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question fetching the background-color from my .alt1 css class

    Hi folks,

    I must have looked for at least a good hour last night trying to figure out the best approach to my new problem.

    I have a style sheet with a certain element I'd like to obtain the background-color property because I've recently stopped using bgcolor="#xxxxxxx" and replaced it with class="alt1" or class="alt2" for my <tr>'s and <td's>.

    The problem begins with the SWF flash object function I have (to prevent the double click for swf movies on the web page). One of the arguments allow me to set the background color but it only takes a hex color such as #333333 but since I've converted my bgcolor= to class= I can no longer access the required hex color to send to the flash object function.

    I would like to now try to access the alt1 or alt2 property of my css sheet, which looks like this:

    HTML Code:
    <!-- css for style 1 -->
    <style id="html" type="text/css">
    <!--
    .alt1 
    {
          background-color: #fffffff
    }
    
    .alt2
    {
          background-color: #ebebeb
    }
    //-->
    </style>
    Could someone help me? Thanks in advance..

    Peter

  2. #2
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I use the following:

    Code:
    function getStyle(oElm, strCssRule){
        var strValue = "";
        if(document.defaultView && document.defaultView.getComputedStyle){
            strValue = document.defaultView.getComputedStyle(oElm, "").getPropertyValue(strCssRule);
        } else if(oElm.currentStyle) {
            strCssRule = strCssRule.replace(/\-(\w)/g, function (strMatch, p1){
                return p1.toUpperCase();
            });
            strValue = oElm.currentStyle[strCssRule];
        }
        return strValue;
    }
    Code:
    var res = getStyle(document.getElementById('someelement'), 'background-color');



Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •