Note that there are some explanatory texts on larger screens.

plurals
  1. POJavaScript (jQuery) for-loop question
    primarykey
    data
    text
    <p>Hey all, I'm new to JavaScript and I'm using the jQuery library for this. Basically I'm trying to create multiples of this line and I'm using ":eq(0) to do it. The issue is that :eq(0) repeats 3 times in the code and with the loop that I'm doing every time it repeats it has a different number.</p> <p>This is what I'm getting from it i think (:eq(0), :eq(1),:eq(2), :eq(3), etc..) I need it to do this (:eq(0),:eq(0),:eq(0), :eq(1) :eq(1) :eq(1), etc...)</p> <pre><code>for (i = 0; i &lt; 6; ++i) { var $titleMarquee = '&lt;marquee scrollamount="5" direction="left" width="233" align="left" behavior="alternate" loop="1"&gt;&lt;span&gt;'; var $lieq = "li:eq("+i+")"; $("ul.side-block-content "+$lieq+"").mouseenter(function() { $("ul.side-block-content "+$lieq+" .article-title a span") .replaceWith($titleMarquee+$("ul.side-block-content "+$lieq+" .article-title a").text()+"&lt;/span&gt;&lt;/marquee&gt;"); }); } </code></pre> <p>If anyone can let me know how to do this loop correctly, or maybe how to recreate the code for it to do the same thing that would be great.</p> <p>Thanks in advance.</p> <p>@Nick's answer:</p> <pre><code>var $titleMarquee = '&lt;marquee scrollamount="5" direction="left" width="233" align="left" behavior="alternate" loop="1"&gt;&lt;span&gt;'; for (i = 0; i &lt; 6; ++i) { for (j = 0; j &lt; 7; ++j) { $("ul.side-block-content li:eq("+i+")").mouseenter(function(){$("ul.side-block-content li:eq("+i+") .article-title a span").replaceWith($titleMarquee+$("ul.side-block-content li:eq("+i+") .article-title a").text()+"&lt;/span&gt;&lt;/marquee&gt;");}); $("ul.side-block-content li:eq("+i+")").mouseleave(function(){$("ul.side-block-content li:eq("+i+") .article-title a marquee").replaceWith('&lt;span&gt;'+$("ul.side-block-content li:eq("+i+") .article-title a").text()+"&lt;/span&gt;");}); } } </code></pre> <p>This is what I'm using now and it's not working. Am I doing it correctly?</p> <p>@Gilly3</p> <pre><code>$("ul.side-block-content li marquee").each(function() { this.stop(); // prevent the marquee from scrolling initially }).mouseenter(function() { this.start(); // start the scroll onmouseenter }); &lt;marquee scrollamount="5" direction="left" width="233" align="left" behavior="alternate"&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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