je confirme bien évidement ce qui est dit
Ca plante
Ca marche
Code html : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12 <!DOCTYPE html> <html> <head> <script type="text/javascript"> var top = 50; // ICI cela ne marche pas BODY n'est pas encore defini document.body.innerHTML += '<div style="position:absolute;top:' +top +'%">ICI<\/div>' </script> </head> <body> </body> </html>
ou encore
Code html : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12 <!DOCTYPE html> <html> <head> </head> <body> <script type="text/javascript"> var top = 50; // ICI cela marche BODY est defini document.body.innerHTML += '<div style="position:absolute; top:'+top +'%">ICI<\/div>' </script> </body> </html>
Code html : 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 <!DOCTYPE html> <html> <head> <script type="text/javascript"> window.onload = function(){ var oDiv = document.createElement('DIV'); oDiv.style.position = 'absolute'; oDiv.style.top = '50%'; var oTxt = document.createTextNode('ICI'); oDiv.appendChild( oTxt); document.body.appendChild( oDiv); } </script> </head> <body> </body> </html>
Partager