Jquery --> Hoping To Add If Statement To While Loop
Posted: Fri Oct 16, 2009 2:01 pm
Hey,
I am a jquery noob but I am slowly getting it. The thing is, I have this free piece of code I am reverse engineering
that is the guts of a multi-star rating system. The part that determines which CSS class to use (hover) depending on the rating (I go from -5 to 5)
is all located in this while statement:
What this is doing is saying "If the value is greater than -6, and a mouse goes over it, take the 'hover' css class for the
specific star. Ok, no problem. My goal is to get that piece of code to say, within the loop
If hover == 5, use .addClass("hover5")
If hover == 4 use .addClass("hover4")
...
if hover ==-5 use .addClass("hovern5)
The idea is that while the loop is working, I want to use 10 conditionals and use 10 unique CSS classes
instead of being forced to use .hover. For reference, the .hover class tells the star to go fro a blank star to a filled up one
But I want to use 10 stars with 10 different hover images. Hence, 10 css classes are idea for me (hover 1 - 10 or something like that)
Is THAT possible? To have the if hover == conditional, for each value, in that loop?
Thanks
I am a jquery noob but I am slowly getting it. The thing is, I have this free piece of code I am reverse engineering
that is the guts of a multi-star rating system. The part that determines which CSS class to use (hover) depending on the rating (I go from -5 to 5)
is all located in this while statement:
Code: Select all
while(hovered > -6) {
$("#rating_"+rid).children(".star_"+hovered).children('img').addClass("hover");
hovered--;
}
specific star. Ok, no problem. My goal is to get that piece of code to say, within the loop
If hover == 5, use .addClass("hover5")
If hover == 4 use .addClass("hover4")
...
if hover ==-5 use .addClass("hovern5)
The idea is that while the loop is working, I want to use 10 conditionals and use 10 unique CSS classes
instead of being forced to use .hover. For reference, the .hover class tells the star to go fro a blank star to a filled up one
But I want to use 10 stars with 10 different hover images. Hence, 10 css classes are idea for me (hover 1 - 10 or something like that)
Is THAT possible? To have the if hover == conditional, for each value, in that loop?
Thanks