l'alert me retourne pourant bien le bon élément ???
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;"> </div> <div id='two' style="background-color:silver;"> </div> </body> <script type='text/javascript'> var newDiv=document.createElement('div') newDiv.style.backgroundColor='lightgreen' newDiv.innerHTML=" " var the_body = document.getElementsByTagName('body')[0]; alert(the_body.firstChild.style.backgroundColor) the_body.firstChild.insertBefore(newDiv); //mybody.firstChild.insertBefore(newDiv) </script> </html>
Partager