JavaScript Reference/Javascript Objects/rule

Материал из Web эксперт
Перейти к: навигация, поиск

"rule" Example

    
<html>
<head>
<style>
#myP { font-family:verdana, arial; font-weight:bold; font-size:16px; }
</style>
<script language="JavaScript">
function function1() {
    var myRule = document.styleSheets(0).rules(0);
    var n = myRule.selectorText;
    alert(n); 
} 
</script>
</head>
<body>
<p id="myP">This is the text with a specific style rule applied.</p>
<input type="button" 
       value="Click here to view the styleSheet selector" 
       onclick="function1();">
</body>
</html>



"rule" is applied to

Names noted with an asterisk (*) are JavaScript properties only.
+----------------+--------------------------------------------------------------+
| Applied_To     |rules*                                                        |
+----------------+--------------------------------------------------------------+



"rule" JavaScript Objects

+----------------+--------------------------------------------------------------+
| JavaScript     |style                                                         |
+----------------+--------------------------------------------------------------+



"rule" JavaScript Properties

+----------------+--------------------------------------------------------------+
| JavaScript     |readOnly                        selectorText                  |
+----------------+--------------------------------------------------------------+



"rule" Syntax and Note

Note:
Affect a specific rule in a style sheet. 
You can only access the rule object by referencing the desired index in the 
rules collection.
    
Syntax:
    
document.styleSheets(index1).rules(index2).memberName