Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #27021

Re: set/get a data attribute, for loop closure prob

From "Christoph M. Becker" <cmbecker69@arcor.de>
Newsgroups comp.lang.javascript
Subject Re: set/get a data attribute, for loop closure prob
Date 2015-03-13 02:58 +0100
Organization solani.org
Message-ID <mdtg7s$338$1@solani.org> (permalink)
References <d01ca00f-f84a-4d29-a94b-bd42426addbc@googlegroups.com>

Show all headers | View raw


JRough wrote:

> I have a jsfiddle,  http://jsfiddle.net/jlrough/wq95ycr5/
> the images are missing but  I can tell you what it is doing.  If you click the previous or next  links it moves the carousel image forward or backward okay.  
> 
> The problem is when you do the hover.  Whichever dot you hover on it makes all the images go forward to the end instead of stopping on the one you hover on.
> 
> The error I'm trying to fix is the For loop which is a closure.  The hover function should not get the value of i from the For loop.  So as a hack to solve it I tried to put the value of i in a data attribute.    However it doesn't seem like my data method is setting or getting the data attribute.   TIA,

Just a quick note.  Don't use this:

  for (var i = 0; i < $('.carousel-dots-nav-item').length; i++) {

but *rather* something like:

  $(".carousel-dots-nav-item").each(...)

That should solve your binding issues.

-- 
Christoph M. Becker

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

set/get a data attribute,  for loop closure prob JRough <janis.rough@gmail.com> - 2015-03-11 20:32 -0700
  Re: set/get a data attribute,  for loop closure prob "Christoph M. Becker" <cmbecker69@arcor.de> - 2015-03-13 02:58 +0100
  Re: set/get a data attribute,  for loop closure prob JRough <janis.rough@gmail.com> - 2015-03-13 09:47 -0700

csiph-web