仿¥ã¯ãã¾ã ã¾ã Safari 3 ãç±ãï¼
window ãªãã¸ã§ã¯ããèµ°æ»ãã¦ããããã¾ããã¦ãé¢ç½ãããªé¢æ°ãè¦ã¤ãã¦ãã¾ã£ãã
ãã®åã getMatchedCSSRules ï¼ï¼ï¼
ã¾ãã¯ãã¢ãã覧ãã ãã
以ä¸ã®ããã¯ãã¼ã¯ã¬ãããä»»æã®ãµã¤ãã§å®è¡ããã¨ãã³ã³ãã³ãã®ä¸ã« DOM Inspector ã®ãããªè¦ç´ ãåºç¾ãã¾ãã
ããã§ãè¦ç´ ãéãã¦ãã㨠Safari ã®å ´åã¯ãã©ã® CSS ã«ã¼ã«ãå½ãã£ã¦ããããè¦ãäºãã§ãã¾ãã
javascript:(function(){var d=document,s=d.createElement('script');s.className='css-inspector-script';d.body.appendChild(s);s.src='http://amachang.art-code.org/cssInspector.js'})()
å®éã«ä½¿ã£ã¦ããæ§å
http://amachang.art-code.org/cssInspector.htm
ããã¯ã getMatchedCSSRules 颿°ã使ã£ã¦ã©ã® CSS ã«ã¼ã«ãè¦ç´ ã«å½ãã£ã¦ããããåãäºãã§ããããç°¡åã«å®è£ ã§ãã¾ãã
getMatchedCSSRules ã®ä½¿ããã
ãããªæã
var rules = getMatchedCSSRules(element, ''); if (rules) { for (var i = 0; i < rules.length; i ++) { var rule = rules[i]; alert(rule.selectorText); alert(rule.style.color); alert(rule.style.backgroundColor); } }
弿°
第ä¸å¼æ°ã¯å¯¾è±¡è¦ç´ ã
第äºå¼æ°ã¯çä¼¼è¦ç´ ãæå®ããå ´åã«ä½¿ããé常ã¯ç¬¬äºå¼æ°ã¯ç©ºæååã§ããã
第ä¸å¼æ°ã¯ããããããï¼ï¼
åãããªãã¸ã§ã¯ãã¯
CSSRuleList âãã
// Introduced in DOM Level 2: interface CSSRuleList { readonly attribute unsigned long length; CSSRule item(in unsigned long index); };http://www.w3.org/TR/DOM-Level-2-Style/css.html#CSS-CSSRuleList
JavaScript ã§ã¯ãé åã£ã½ã使ããã®ã§ãããªæãã§åãã
for (var i = 0; i < rules.length; i ++) { var rule = rules[i] }
ã§ãrules[i] ã¯âããã§
// Introduced in DOM Level 2: interface CSSStyleRule : CSSRule { attribute DOMString selectorText; // raises(DOMException) on setting readonly attribute CSSStyleDeclaration style; };http://www.w3.org/TR/DOM-Level-2-Style/css.html#CSS-CSSStyleRule
âããã¯âãããç¶æ¿ãã¦ã
// Introduced in DOM Level 2: interface CSSRule { // RuleType const unsigned short UNKNOWN_RULE = 0; const unsigned short STYLE_RULE = 1; const unsigned short CHARSET_RULE = 2; const unsigned short IMPORT_RULE = 3; const unsigned short MEDIA_RULE = 4; const unsigned short FONT_FACE_RULE = 5; const unsigned short PAGE_RULE = 6; readonly attribute unsigned short type; attribute DOMString cssText; // raises(DOMException) on setting readonly attribute CSSStyleSheet parentStyleSheet; readonly attribute CSSRule parentRule; };http://www.w3.org/TR/DOM-Level-2-Style/css.html#CSS-CSSRule
ãªã®ã§ã
alert(rule.cssText); // .hoge#fuga { color: rgb(255, 0, 0); width: 100%; } alert(rule.selectorText); // .hoge#fuga alert(rule.style.cssText);// color: rgb(255, 0, 0); width: 100%; alert(rule.style.color); // rgb(255, 0, 0) alert(rule.style.width); // 100% alert(rule.parentStyleSheet.href); // http://hoge.ho.ge/fuga.css
ã¿ãããªããã¹ããç°¡åã«ã¨ãã¦ãã¾ãï¼
ã¾ã¨ã
ãã©ä¾¿å©ï¼ï¼ï¼
ã¡ãªã¿ã«ä»æ§æ¸ã£ã½ããã®ã¯ http://webkit.org/docs/a00029.html ãããããããè¦å½ãããªãã