Baseline Widely available
CSSStyleSheet.insertRule() ã¡ã½ããã¯ãæ°ãã CSS ã«ã¼ã«ãç¾å¨ã®ã¹ã¿ã¤ã«ã·ã¼ãã«æ¿å ¥ãã¾ãã
ã¡ã¢: insertRule()
㯠CSSStyleSheet
å°ç¨ã®ã¡ã½ããã§ãããå®éã«ã¯ã«ã¼ã«ã CSSStyleSheet.cssRules
ã«ãå
é¨çã«ã¯ CSSRuleList
ã«æ¿å
¥ãã¾ãã
insertRule(rule)
insertRule(rule, index)
弿°
rule
æ¿å ¥ãããã«ã¼ã«ãå ¥ã£ãæååã§ããã©ã®ãããªã«ã¼ã«ãæ¿å ¥ãããã¯ã種é¡ã«ããã¾ãã
index
çç¥å¯
stylesheet.cssRules.length
以ä¸ã®æ£ã®æ°ã§ã CSSStyleSheet.cssRules
ã®ä¸ã§æ°ããæ¿å
¥ãããã«ã¼ã«ã®ä½ç½®ã示ãã¾ããæ¢å®å¤ã¯ 0
ã§ããï¼å¤ãå®è£
ã§ã¯ãããã¯å¿
é ã§ããã詳ããã¯ãã©ã¦ã¶ã¼ã®äºææ§ãåç
§ãã¦ãã ãããï¼
ã¹ã¿ã¤ã«ã·ã¼ãã®ã«ã¼ã«ãªã¹ãå ã®ãæ°ãã«æ¿å ¥ãããã«ã¼ã«ã®ä½ç½®ã§ãã
ä¾å¤IndexSizeError
DOMException
index
> CSSRuleList.length
ã®å ´åã«çºçãã¾ãã
HierarchyRequestError
DOMException
CSS ã®å¶ç´ä¸ãrule
ã index
0
ã«æ¿å
¥ã§ããªãå ´åã«çºçãã¾ãã
SyntaxError
DOMException
rule
弿°ã« 2 ã¤ä»¥ä¸ã®ã«ã¼ã«ãä¸ããããå ´åã«çºçãã¾ãã
HierarchyRequestError
DOMException
ã¹ã¿ã¤ã«ã«ã¼ã«ã®å¾ã« @import
ã¢ããã«ã¼ã«ãæ¿å
¥ãããã¨ããå ´åã«çºçãã¾ãã
InvalidStateError
DOMException
rule
ã @namespace
ã§ãããã«ã¼ã«ãªã¹ãã« @import
ã¢ããã«ã¼ã«ã @namespace
ã¢ããã«ã¼ã«ä»¥å¤ã®ãã®ããã£ãå ´åã«çºçãã¾ãã
ãã®ã¹ããããã¯ãæ°ããã«ã¼ã«ãã¹ã¿ã¤ã«ã·ã¼ãã®å é ã«è¿½å ãã¾ãã
myStyle.insertRule("#blanc { color: white }", 0);
ã¹ã¿ã¤ã«ã·ã¼ãã«ã¼ã«ã追å ãã颿°
/**
* Add a stylesheet rule to the document (it may be better practice
* to dynamically change classes, so style information can be kept in
* genuine stylesheets and avoid adding extra elements to the DOM).
* Note that an array is needed for declarations and rules since ECMAScript does
* not guarantee a predictable object iteration order, and since CSS is
* order-dependent.
* @param {Array} rules Accepts an array of JSON-encoded declarations
* @example
addStylesheetRules([
['h2', // Also accepts a second argument as an array of arrays instead
['color', 'red'],
['background-color', 'green', true] // 'true' for !important rules
],
['.myClass',
['background-color', 'yellow']
]
]);
*/
function addStylesheetRules(rules) {
const styleEl = document.createElement("style");
// Append <style> element to <head>
document.head.appendChild(styleEl);
// Grab style element's sheet
const styleSheet = styleEl.sheet;
for (let i = 0; i < rules.length; i++) {
let j = 1,
rule = rules[i],
selector = rule[0],
propStr = "";
// If the second argument of a rule is an array of arrays, correct our variables.
if (Array.isArray(rule[1][0])) {
rule = rule[1];
j = 0;
}
for (let pl = rule.length; j < pl; j++) {
const prop = rule[j];
propStr += `${prop[0]}: ${prop[1]}${prop[2] ? " !important" : ""};\n`;
}
// Insert CSS Rule
styleSheet.insertRule(
`${selector}{${propStr}}`,
styleSheet.cssRules.length,
);
}
}
仿§æ¸ ãã©ã¦ã¶ã¼ã®äºææ§ é¢é£æ
å ±
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4