Link to home
Start Free TrialLog in
Avatar of badwolfff
badwolfffFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Why is my Jquery code behaving strangely?

Hi

Within the HTML file you will find that I have 5 child divs under the #sitedivs.

With this line of code I am trying to set each of the children's css "left" value
for (i=0; i<$("#sitedivs").children().length-1; i++)							
{
	$("#sitedivs div:eq(i)").css("left", i*$(window).width()+"px" );
	//alert(i);
}

Open in new window


Strangely this code does nothing at all.
However if instead of "i" value I were to put in real numerical values, it work, as shown below:
 
$("#sitedivs div:eq(3)").css("left",3*$(window).width()+"px" );

Open in new window


Please help as this is damned maddening!

thanks in advance
SITO.zip
Avatar of Lukasz Chmielewski
Lukasz Chmielewski
Flag of Poland image

Try this:

					var ww = $(window).width();
					var lft = i*ww;
					$("#sitedivs div:eq("+i+")").css("left", lft+"px" );

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Lukasz Chmielewski
Lukasz Chmielewski
Flag of Poland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial