Pregunta

I am using jquery to dynamically create an active state using Flexslider's API. Here is my jQuery:

var curslide = slider.animatingTo;
var parsed = parseInt(curslide);

$("#pillarControl li").each(function(){
     $(this).removeClass("active");
});

$("#pillarControl  li a[rel='parsed']").parent().addClass("active");

THe bottom line is NOT working. If I replace parsed with an actual integer, it works great. But for some reason, the variable parsed is not causing the active class to be added. I did a test to see if the variable parsed had the correct value stored, and it does. Seems to be a syntax problem? Not sure, any ideas?

¿Fue útil?

Solución

The problem is that you don't pass the variable value, but just 'parsed' as text. Try:

$("#pillarControl  li a[rel='" + parsed + "']").parent().addClass("active");

Otros consejos

Try this:

$("#pillarControl  li a[rel='" + parsed + "']").parent().addClass("active");

You seem to be passing parsed as a string . You need to pass the

var parsed = parseInt(curslide);

So your old selector is looking with rel="parsed" and not the value of parsed..

$("#pillarControl  li a[rel='" + parsed + "']").parent().addClass("active");
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top