JCHASE11
JCHASE11

Reputation: 3941

Dynamic rel Selector not working

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?

Upvotes: 0

Views: 181

Answers (3)

Sushanth --
Sushanth --

Reputation: 55750

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");

Upvotes: 0

DmitriG
DmitriG

Reputation: 98

Try this:

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

Upvotes: 0

Michal Klouda
Michal Klouda

Reputation: 14521

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");

Upvotes: 5

Related Questions