OVH Cloud OVH Cloud

Infos sur getElementById

3 réponses
Avatar
mv1
Bonjour,

Comment sait-on quand on doit utiliser getElementById('XX').value ou
getElementById('XX').innerHTML ?
Quand l'un marche, l'autre ne fonctionne plus ... je ne trouve aucune
précision sur ces 2 fonctions ...

Merci
- mv1 -

3 réponses

Avatar
CrazyCat
mv1 wrote:
Bonjour,

Comment sait-on quand on doit utiliser getElementById('XX').value ou
getElementById('XX').innerHTML ?
Quand l'un marche, l'autre ne fonctionne plus ... je ne trouve aucune
précision sur ces 2 fonctions ...


Globalement, la réponse est dans le nom de la méthode:
.value => il doit donc s'agir d'un champ dont on peut analyser la valeur
(un input)
.innerHTML => il s'agit d'un élément HTML dont on prend le contenu (un
bloc HTML)

--
Astuces informatiques: http://www.crazycat.info
Tchattez en liberté: http://www.crazy-irc.net

Avatar
bruno at modulix
CrazyCat wrote:
mv1 wrote:

Bonjour,

Comment sait-on quand on doit utiliser getElementById('XX').value ou
getElementById('XX').innerHTML ?
Quand l'un marche, l'autre ne fonctionne plus ... je ne trouve aucune
précision sur ces 2 fonctions ...



<pedant>
s/fonctions/attributs/
</pedant>


Globalement, la réponse est dans le nom de la méthode:


<pedant>
s/méthode/attribut/
</pedant>

.value => il doit donc s'agir d'un champ dont on peut analyser la valeur
(un input)
.innerHTML => il s'agit d'un élément HTML dont on prend le contenu (un
bloc HTML)




--
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in ''.split('@')])"


Avatar
Bertrand B
Bonjour,

Comment sait-on quand on doit utiliser getElementById('XX').value ou
getElementById('XX').innerHTML ?
Quand l'un marche, l'autre ne fonctionne plus ... je ne trouve aucune
précision sur ces 2 fonctions ...

Merci
- mv1 -


Ce n'est pas lié à la fonction getElementById.

Celle-ci retourne un objet et cet objet a ou n'a pas la propriété
innerHTML ou value.
Si tu ne comprends pas utilise firefox et avec son "Dom inspector"
vérifies quelles propriétés et méthodes possède l'élément q ue tu
cherches à adresser par getElementById.

(je ne fais pas la promotion de firefox mais je ne saurais pas me passer
de "Dom inspector"

(vais je avoir aussi une corection pour avoir utilisé méthode ?)