Fichier js externe ne trouve pas id
Bonjour,
J'ai un fichier main.php :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| <!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="test.js"></script>
</head>
<script>
window.onload = function()
{
f();
}
</script>
<body>
<div id='msg'></div>
</body>
</html> |
.. un fichier tab.php :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| <!DOCTYPE html>
<html>
<body>
<table id="45">
<tr>
<th></th>
<th>TOTO</th>
<th>TATA</th>
</tr>
<tr>
<td>A</td>
<td>2</td>
<td>6</td>
</tr>
<tr>
<td>B</td>
<td>7</td>
<td>9</td>
</tr>
</table>
</body>
</html> |
.. et un fichier test.js :
Code:
1 2 3 4 5
| function f()
{
var tab = document.getElementById('45').rows;
document.getElementById('msg').innerHTML = tab[1].cells[1].innerHTML;
} |
Ces trois fichiers sont placés dans le même dossier. J'ai dû rater quelque chose au niveau des fichier .js, mais tout se passe comme s'il trouvait sans problèmes l'id msg, mais ne trouve pas l'id 45..
Avez-vous déjà eu ce problème ? :)
Merci pour vos réponses !