Dom CSS : Objet StyleSheet.parentStyleSheet

La propriété javascript parentStyleSheet

Définition

L'attribut javascript StyleSheet.parentStyleSheet permet de connaître la feuille de style contenant cette règle.
Exemple de code :
<style type="text/css" id="parentStyleSheet">
  @import url("test_ParentStyleSheet.css");
</style>

/*
Dans cet exemple nous considérons que styleSheet est un objet de type interface StyleSheet qui est la feuille de style de id="parentStyleSheet"
*/
alert(styleSheet.parentStyleSheet);
//null
/*
On récupère la régle @import
*/
var Import = styleSheet.cssRules.item(0).
/*
On récupère interface StyleSheet d'@import
*/
var styleSheetImport = Import.styleSheet
alert(styleSheetImport.parentStyleSheet);
//object CSSStyleSheet

Valeur retournée de parentStyleSheet

Valeur retournée

L'attribut javascript StyleSheet.parentStyleSheet renvoie :
- objet CSSStyleSheet, si la StyleSheet est incluse
- null, si la StyleSheet n'est pas incluse