Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<body>
<div id='one' style="background-color:red;">&nbsp;</div>
<div id='two' style="background-color:silver;">&nbsp;</div>
 
 
</body>
<script type='text/javascript'>
var newDiv=document.createElement('div')
newDiv.style.backgroundColor='lightgreen'
newDiv.innerHTML="&nbsp;"
var the_body = document.getElementsByTagName('body')[0];
alert(the_body.firstChild.style.backgroundColor)
the_body.firstChild.insertBefore(newDiv);
 
//mybody.firstChild.insertBefore(newDiv)
</script>
 
</html>
l'alert me retourne pourant bien le bon élément ???