Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Oct 2008
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Macintosh my javascript isnt working :( {simple}

    Could someone please take alook at my code it just isnt changing the class when i click on an <a> tag.

    Code:
    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
    Last edited by cmplieger; 10-10-2008 at 06:16 PM.

  • #2
    Banned
    Join Date
    May 2006
    Location
    England
    Posts
    664
    Thanks
    0
    Thanked 84 Times in 84 Posts
    Quote Originally Posted by cmplieger View Post
    Code:
    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.

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

  • #3
    New to the CF scene
    Join Date
    Oct 2008
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Arty Effem View Post
    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

    Thanks a lot!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •