use jquery to add an acrive class

I am trying to add an active class to the 1,2,3 buttons on this slider
http://gromit.utopia.co.nz/~safeware/newsslider/index.html

IE, if slider 1 is showing then class="active" is added to the Number 1 button etc..
Can anyone assist?
Cheers,
N
LVL 5
Neil_BradleyWeb UX/UI DeveloperAsked:
Who is Participating?
 
leakim971PluritechnicianCommented:
add the following at line 90 (just after next_excerpt.addClass('selected');)  :

var n = $("#gallery li").index($("#gallery li.selected"));
$("#buttons").next("div").find("a.active").removeClass("active");
//setTimeout('$("#buttons").next("div").find("a:eq(" + n + ")").addClass("active")', 800);
$("#buttons").next("div").find("a:eq(" + n + ")").addClass("active");

Open in new window

0
 
Neil_BradleyWeb UX/UI DeveloperAuthor Commented:
You made that look too easy!
Brilliant solution and appreciate the quick response.
Cheers,
Neil
0
 
Neil_BradleyWeb UX/UI DeveloperAuthor Commented:
Just a quick follow up.
Playing with the code a little and I noticed that when div id="buttons" is wrap in another div the script stops working..
http://gromit.utopia.co.nz/~safeware/newsslider/index.html
Any way to specifically target the #id=buttons?
Cheers,
Neil
0
 
leakim971PluritechnicianCommented:
set an ID for the div where you've the LI, for example : divID <div id="divID">
So instead : $("#buttons").next("div")
use : $("#divID")
0
 
Neil_BradleyWeb UX/UI DeveloperAuthor Commented:
Cheers, that got it.
I am going to open up another question regarding this slider (specifically the active function) as I am keen to go a step further.
Look forward to your participation..
Neil
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.