Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!weretis.net!feeder1.news.weretis.net!news.solani.org!.POSTED!not-for-mail From: "Christoph M. Becker" Newsgroups: comp.lang.javascript Subject: Re: set/get a data attribute, for loop closure prob Date: Fri, 13 Mar 2015 02:58:30 +0100 Organization: solani.org Lines: 21 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Trace: solani.org 1426211900 3176 eJwFwYEBwCAIA7CXLNqyncOQ/n/CEm5BnUfUoWl5rolPV0rF++wpAMxCTsU9mwqU3bPayz8dCBFe (13 Mar 2015 01:58:20 GMT) X-Complaints-To: abuse@news.solani.org NNTP-Posting-Date: Fri, 13 Mar 2015 01:58:20 +0000 (UTC) User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.5.0 X-User-ID: eJwFwYEBACAEBMCVEo/GQf3+I3QHdfEJc7iBIMMsOPIGfbKrwK1crcm7us6T8Lkspa3kxgc1CxH1 In-Reply-To: Cancel-Lock: sha1:DOL2sqndK3bnd0bDZEqqs9YKMSs= X-NNTP-Posting-Host: eJwNwgERwDAIA0BLpZBkyCmU+Zew3T+cxlYQDLw/2FTGLVtZnickatudbYfAKiQ91T0ogc8HCo0QUQ== Xref: csiph.com comp.lang.javascript:27021 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