Function not defined en JS
ankh-ou
-
Dalida Messages postés 6728 Date d'inscription Statut Contributeur Dernière intervention -
Dalida Messages postés 6728 Date d'inscription Statut Contributeur Dernière intervention -
Bonjour,
J'ai un tableau dans mon index, en cliquant sur la ligne de ce tableau je veux changer sa couleur. voici mon code
<div id="Results">
<table align="center" >
<th id="pseudo"></th>
<tr id="1" onclick="changeColor(this.id)"> <td id="song0"></td> </tr>
<tr id="2" onclick="changeColor(this.id)"> <td id="song1"></td> </tr>
<tr id="3" onclick="changeColor(this.id)"> <td id="song2"></td> </tr>
</table>
</div>
et dans le fichier .js
function changeColor(id) {
alert(id);
document.getElementById(id).style.background = '#FFCC33';
}
J'ai un tableau dans mon index, en cliquant sur la ligne de ce tableau je veux changer sa couleur. voici mon code
<div id="Results">
<table align="center" >
<th id="pseudo"></th>
<tr id="1" onclick="changeColor(this.id)"> <td id="song0"></td> </tr>
<tr id="2" onclick="changeColor(this.id)"> <td id="song1"></td> </tr>
<tr id="3" onclick="changeColor(this.id)"> <td id="song2"></td> </tr>
</table>
</div>
et dans le fichier .js
function changeColor(id) {
alert(id);
document.getElementById(id).style.background = '#FFCC33';
}
3 réponses
comme d'habitude je n'ai pas lu le code…
(ô_O)'
essaie avec :
(ô_O)'
essaie avec :
document.getElementById(id).style.backgroundColor = '#FFCC33';
ankh-ou
En même temps :) merci à toi
Dalida
Messages postés
6728
Date d'inscription
Statut
Contributeur
Dernière intervention
922
>
ankh-ou
bien vu, bon courage pour la suite !
salut,
et comment est-ce que tu inclus ton fichier JS ?
est-ce que ça le fait avec tous les navigateurs ?
et comment est-ce que tu inclus ton fichier JS ?
est-ce que ça le fait avec tous les navigateurs ?
as-tu essayé d'ajouter du contenu à tes cellules ?
as-tu essayé de coder le même évènement sur une autre balise, un lien par exemple ?
as-tu essayé de coder le même évènement sur une autre balise, un lien par exemple ?
Problème résolu, c'était à cause de l'attribut du style.
En faisant ça, je peux changer la couleur du texte, le fond de la cellule, et sa hauteur.
Merci quand même.
<div id="Results">
<table align="center" >
<th id="pseudo"></th>
<tr id="1"> <td id="song0" onclick="changeColor(this.id)"></td> </tr>
<tr id="2"> <td id="song1" onclick="changeColor(this.id)"></td> </tr>
<tr id="3"> <td id="song2" onclick="changeColor(this.id)"></td> </tr>
</table>
</div>
-----------------------------------------
function changeColor(id) {
alert(id);
document.getElementById(id).style.backgroundColor = '#FFFFFF';
document.getElementById(id).style.color = "#999999";
document.getElementById(id).style.height = "75px";
}
En faisant ça, je peux changer la couleur du texte, le fond de la cellule, et sa hauteur.
Merci quand même.
<div id="Results">
<table align="center" >
<th id="pseudo"></th>
<tr id="1"> <td id="song0" onclick="changeColor(this.id)"></td> </tr>
<tr id="2"> <td id="song1" onclick="changeColor(this.id)"></td> </tr>
<tr id="3"> <td id="song2" onclick="changeColor(this.id)"></td> </tr>
</table>
</div>
-----------------------------------------
function changeColor(id) {
alert(id);
document.getElementById(id).style.backgroundColor = '#FFFFFF';
document.getElementById(id).style.color = "#999999";
document.getElementById(id).style.height = "75px";
}