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.
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...)
for (i = 0; i < 6; ++i) {
var $titleMarquee = '<marquee scrollamount="5" direction="left" width="233" align="left" behavior="alternate" loop="1"><span>';
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()+"</span></marquee>");
});
}
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.
Thanks in advance.
@Nick's answer:
var $titleMarquee = '<marquee scrollamount="5" direction="left" width="233" align="left" behavior="alternate" loop="1"><span>';
for (i = 0; i < 6; ++i) {
for (j = 0; j < 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()+"</span></marquee>");});
$("ul.side-block-content li:eq("+i+")").mouseleave(function(){$("ul.side-block-content li:eq("+i+") .article-title a marquee").replaceWith('<span>'+$("ul.side-block-content li:eq("+i+") .article-title a").text()+"</span>");});
}
}
This is what I'm using now and it's not working. Am I doing it correctly?
@Gilly3
$("ul.side-block-content li marquee").each(function() {
this.stop(); // prevent the marquee from scrolling initially
}).mouseenter(function() {
this.start(); // start the scroll onmouseenter
});
<marquee scrollamount="5" direction="left" width="233" align="left" behavior="alternate">
marqueehas been deprecated outside of the first child ofblink.blinktag die peacefully.