[DOM] recupération zIndex aléatoire
Si je click "Affiche index2" après le chargement la valeur de retour zIndex est vide.
Si je click "Change index2" puis "Affiche index2" à nouveau l'zIndex vaut 5, normal.
Pourquoi ne vaut-il rien au premier passage alors qu'il est définit dans le CSS avec la valeur 2?
Je ne comprends pas tous sur ce coup :roll:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| <html>
<head>
<title>z-index</title>
<style type="text/css" title="text/css">
body{ background-color: #000;}
#z2{
font-family: arial;
font-size: 12px;
font-weight: bold;
padding: 4px;
border: 2px solid lightgrey;
width: 180px; height: 140px;
position: absolute; left: 75px; top: 80px;
background-color: yellow;
z-index: 2;
}
</style>
</head>
<body>
<button onclick="alert(document.getElementById('z2').style.zIndex);">Affiche index2</button>
<button onclick="document.getElementById('z2').style.zIndex = '5';">Change index 2</button>
<div id=z2>z-index 2</div>
</body>
</html> |