...

View Full Version : my javascript isnt working :( {simple}



cmplieger
10-09-2008, 07:30 PM
Could someone please take alook at my code it just isnt changing the class when i click on an <a> tag.


function addListener(o, e, f) { // object, event, function
if (o.addEventListener) {
o.addEventListener(e, f, false);
} else { // pour MSIE
o.attachEvent('on' + e, f);
}
}

/******************************************************************************/

function changeClass1() {
document.getElementById('content').className='slidedone';
document.getElementById('footer').className='slidedone';
document.getElementById('list').className='slidedone';
}

function changeClass2() {
document.getElementById('content').className='slidedone2'&#173;;
document.getElementById('footer').className='slidedone2';&#173;
document.getElementById('list').className='slidedone2';
}

// il faudra peut-&#234;tre rajouter d'autres fonctions changeClassN

/******************************************************************************/

function bindAnchors() { // fonction pour lier les liens &#224; la fonction changeClass
var collection1 = document.getElementById('topmenu').getElementsByTagName('a')&#173;&#173;;
var collection2 = document.getElementById('content').getElementsByTagName('a')&#173;;
var collection3 = document.getElementById('toprightmenu').getElementsByTagName&#173;('a')&#173;;
var collection4 = document.getElementById('toprightbutton').getElementsByTagNa&#173;me('a')&#173;;

for (var i = 0; i <= collection1.length - 1; i++) {
var lien = collection1.item(i);
addListener(lien, 'click', changeClass2);
}

for (var i = 0; i <= collection2.length - 1; i++) {
var lien = collection2.item(i);
addListener(lien, 'click', changeClass1);
}

for (var i = 0; i <= collection3.length - 1; i++) {
var lien = collection3.item(i);
addListener(lien, 'click', changeClass1); // v&#233;rifier que c'est bien changeClass1 qu doit &#234;tre appel&#233;e ici
}

for (var i = 0; i <= collection4.length - 1; i++) {
var lien = collection4.item(i);
addListener(lien, 'click', changeClass1); // idem
}
}

/******************************************************************************/

// on lie les liens une fois que la page est charg&#233;e, sinon ils n'existent pas encore
// et on le fait avec addListener, pour que &#231;a marche m&#234;me sous IE
addListener(window, 'load', bindAnchors);

thanks a lot

Arty Effem
10-10-2008, 01:23 AM
function changeClass2() {
document.getElementById('content').className='slidedone2'*;
document.getElementById('footer').className='slidedone2';*
document.getElementById('list').className='slidedone2';
}

// il faudra peut-être rajouter d'autres fonctions changeClassN

/******************************************************************************/

function bindAnchors() { // fonction pour lier les liens à la fonction changeClass
var collection1 = document.getElementById('topmenu').getElementsByTagName('a')**;
var collection2 = document.getElementById('content').getElementsByTagName('a')*;
var collection3 = document.getElementById('toprightmenu').getElementsByTagName*('a')*;
var collection4 = document.getElementById('toprightbutton').getElementsByTagNa*me('a')*;
Why do you have those asterisks? If they are in your original code they will cause syntax errors. Always check the error console before asking for help.



var lien = collection2.item(i);Probably better not to use the item method, just use: collection2[i];

cmplieger
10-10-2008, 05:18 PM
Why do you have those asterisks? If they are in your original code they will cause syntax errors. Always check the error console before asking for help.

Probably better not to use the item method, just use: collection2[i];

oops those atars arnt in the original code. I rectified the problem.

Im very very very bad at javascript. Could you explain what you mean by collection2[i]

if you could change the code for me i would be really really thankfull :p

Thanks a lot!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum