Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Why is my Jquery code behaving strangely?

Posted on 2011-10-16
2
Medium Priority
?
182 Views
Last Modified: 2012-05-12
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
0
Comment
Question by:badwolfff
  • 2
2 Comments
 
LVL 27

Expert Comment

by:Lukasz Chmielewski
ID: 36976426
Try this:

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

Open in new window

0
 
LVL 27

Accepted Solution

by:
Lukasz Chmielewski earned 2000 total points
ID: 36976431
Sorry for the tabulators, I guess the problem was with this:
$("#sitedivs div:eq("+i+")")
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to create an extensible mechanism for linked drop downs.
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
Suggested Courses

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question