Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

Niels Bosma www.bosma-development.com

« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS 

Reading attribute values from a stylesheet

Used for reading a value from the loaded stylesheet. Only support the usage of one stylesheet file. Supports selectors beeing grouped and defined in multiple blocks.

   1  
   2  function getCssValue(selector,attribute)
   3     {
   4        selector = selector.toLowerCase();
   5        var stylesheet = document.styleSheets[0];
   6        var n = stylesheet.cssRules.length;
   7        for(var i=0; i<n; i++)
   8        {
   9           var selectors = stylesheet.cssRules[i].selectorText.toLowerCase().split(",");
  10           var m = selectors.length;
  11           for(j=0; j<m; j++)
  12           {
  13              if(selectors[j].trim() == selector)
  14              {
  15                 var value = stylesheet.cssRules[i].style.getPropertyValue(attribute);
  16                 if(value!="")
  17                 {
  18                    return value;
  19                 }
  20              }
  21           }
  22        }
  23        debug("Could not find selector/attribute: "+selector+"/"+attribute);
  24        return null;
  25     },
« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS