getElementById

getElementById - HTML/CSS - Programmation

Marsh Posté le 26-08-2005 à 12:01:33    

slt,
j'utilise getElementById pour modifier des div.
or je veux modifier toutes mes div( qui portes toutes le meme Id)
et getElementById ne me modifie que la 1ere.
comment cela ce fait t-il
si quelqu'un peut m'eclaircir?!?
 
merci d'avance

Reply

Marsh Posté le 26-08-2005 à 12:01:33   

Reply

Marsh Posté le 26-08-2005 à 12:03:19    

zizou771 a écrit :

toutes mes div( qui portes toutes le meme Id)


Un ID est un identifiant unique d'un objet sur une page, deux objets de la même page ne peuvent pas légalement porter le même ID


---------------
I mean, true, a cancer will probably destroy its host organism. But what about the cells whose mutations allow them to think outside the box by throwing away the limits imposed by overbearing genetic regulations? Isn't that a good thing?
Reply

Marsh Posté le 26-08-2005 à 12:06:58    

ben les miens si, il sont crée comme ca
sinon y a getElementByName mais ca marche pas apparement?!?

Reply

Marsh Posté le 26-08-2005 à 12:15:26    

zizou771 a écrit :

ben les miens si, il sont crée comme ca


...
 
Ok, maintenant tu démarres les neurones 5 secondes, tu relis ma phrase et tu te dis que c'est peut être parce que tu tentes de faire un truc illégal que ça fonctionne pas [:itm]

Citation :

sinon y a getElementByName mais ca marche pas apparement?!?


[:petrus75]
 
non, ya pas getElementByName [:petrus75]
 
Il y a getElementsByName, qui est déprécié et n'est plus censé être utilisé, et getElementsByTagName  [:petrus75]


---------------
I mean, true, a cancer will probably destroy its host organism. But what about the cells whose mutations allow them to think outside the box by throwing away the limits imposed by overbearing genetic regulations? Isn't that a good thing?
Reply

Marsh Posté le 26-08-2005 à 12:24:14    

ouais mais getElementsByTagName j'ai essayé c + chaud a faire fonctionner.
j'ai 2 div dans ma page.
 
qd j'lui fait:
 
var objet = document.getElementsByTagName("div" );
alert(objet.length);
 
il m'affiche 1
why ?!?

Reply

Marsh Posté le 26-08-2005 à 12:27:10    

parce qu'il a trouvé un seul div dans la page [:spamafote]


---------------
I mean, true, a cancer will probably destroy its host organism. But what about the cells whose mutations allow them to think outside the box by throwing away the limits imposed by overbearing genetic regulations? Isn't that a good thing?
Reply

Marsh Posté le 26-08-2005 à 12:32:44    

non ok je sais comment faire:
 
var mesDiv = document.getElementsByTagName("div" );
 
for(i in mesDiv){
mesDiv[i].style.visibility="hidden";
}

Reply

Marsh Posté le 26-08-2005 à 12:33:32    

mais mesDiv[0] fonctionne
mais mesDiv[1] fonctionne
mais mesDiv[i] fonctionne pas ???!!!!????

Reply

Marsh Posté le 26-08-2005 à 12:37:14    

document.getElementsByTagName retourne une nodeList, la nodeList n'a pas d'itérateur défini dessus, faudrait apprendre à coder en javascript ptet [:pingouino]


---------------
I mean, true, a cancer will probably destroy its host organism. But what about the cells whose mutations allow them to think outside the box by throwing away the limits imposed by overbearing genetic regulations? Isn't that a good thing?
Reply

Marsh Posté le 26-08-2005 à 12:43:17    

et ben si ca fonctionne comme ca desolé :)
faut juste faire
 
i=mesDiv.length-1;
while(i >= 0 ){
mesDiv[i].style.visibility="hidden";
 
ca marche nikel !!

Reply

Marsh Posté le 26-08-2005 à 12:43:17   

Reply

Marsh Posté le 26-08-2005 à 12:45:32    

pourquoi tu fais pas tout simplement

for(var i=0; i<mesDiv.length; ++i) {
    mesDiv[i].style.visibility="hidden";
}


---------------
I mean, true, a cancer will probably destroy its host organism. But what about the cells whose mutations allow them to think outside the box by throwing away the limits imposed by overbearing genetic regulations? Isn't that a good thing?
Reply

Marsh Posté le 26-08-2005 à 12:58:53    

ouais c mieux :)

Reply

Marsh Posté le 26-08-2005 à 13:04:04    

Et si t'es finaud, tu fais même

for(var i=mesDiv.length-1; i>=0; --i) {
    mesDiv[i].style.visibility="hidden";
}


parce que ça va entre 10 et 50% plus vite en fonction du navigateur (~10% sous MSIE, ~50% sous Firefox), et que sur des itérations sur plusieurs centaines ou milliers d'éléments ça se sent


Message édité par masklinn le 26-08-2005 à 13:04:32

---------------
I mean, true, a cancer will probably destroy its host organism. But what about the cells whose mutations allow them to think outside the box by throwing away the limits imposed by overbearing genetic regulations? Isn't that a good thing?
Reply

Sujets relatifs:

Leave a Replay

Make sure you enter the(*)required information where indicate.HTML code is not allowed