Note that there are some explanatory texts on larger screens.

plurals
  1. POJavaScript for-loop little prob
    text
    copied!<p>I've got a little problem here with the for-loop:</p> <pre><code>var wide = "700px"; var flat = "5px"; var pages = new Array("home","links","aktuell","kontakt"); for(var i=0;i&lt;pages.length;i++) { $("."+pages[i]).bind("click", function() { for(var j=0;j&lt;pages.length;j++) { var width; if(pages[j] != pages[i]) width = flat; else width = wide; $("#"+pages[j]).animate({width: width}, "slow"); } }); $("#"+pages[i]).bind("click", function() { for(var k=0;k&lt;pages.length;k++) { var width; if(pages[k] != pages[i]) width = flat; else width = wide; $("#"+pages[k]).animate({width: width}, "slow"); } }); } </code></pre> <p>actually it should produce the following output, but why doesn't it?</p> <pre><code> $(".home").bind("click", function() { $("#home").animate({width: wide}, "slow"); $("#links").animate({width: flat}, "slow"); $("#aktuell").animate({width: flat}, "slow"); $("#kontakt").animate({width: flat}, "slow"); }); $("#home").bind("click", function() { $("#home").animate({width: wide}, "slow"); $("#links").animate({width: flat}, "slow"); $("#aktuell").animate({width: flat}, "slow"); $("#kontakt").animate({width: flat}, "slow"); }); $(".links").bind("click", function() { $("#links").animate({width: wide}, "slow"); $("#home").animate({width: flat}, "slow"); $("#aktuell").animate({width: flat}, "slow"); $("#kontakt").animate({width: flat}, "slow"); }); $("#links").bind("click", function() { $("#links").animate({width: wide}, "slow"); $("#home").animate({width: flat}, "slow"); $("#aktuell").animate({width: flat}, "slow"); $("#kontakt").animate({width: flat}, "slow"); }); $(".aktuell").bind("click", function() { $("#links").animate({width: flat}, "slow"); $("#home").animate({width: flat}, "slow"); $("#aktuell").animate({width: wide}, "slow"); $("#kontakt").animate({width: flat}, "slow"); }); $("#aktuell").bind("click", function() { $("#links").animate({width: flat}, "slow"); $("#home").animate({width: flat}, "slow"); $("#aktuell").animate({width: wide}, "slow"); $("#kontakt").animate({width: flat}, "slow"); }); $(".kontakt").bind("click", function() { $("#links").animate({width: flat}, "slow"); $("#home").animate({width: flat}, "slow"); $("#aktuell").animate({width: flat}, "slow"); $("#kontakt").animate({width: wide}, "slow"); }); $("#kontakt").bind("click", function() { $("#links").animate({width: flat}, "slow"); $("#home").animate({width: flat}, "slow"); $("#aktuell").animate({width: flat}, "slow"); $("#kontakt").animate({width: wide}, "slow"); }); </code></pre> <p>Can someone find the error? I've tried to give it all as output and it worked fine but when I try to use it on the website it's just not working.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload