views:

18

answers:

1

Hi, I am using Jquery Accordion with a UL contained within each section and I cant figure out how to add a class to indicate the active link.

I have searched my head-off but the only thing I can find doesnt work with the Accordion:

$(document).ready(function(){
  var path = location.pathname.substring(1);
  if ( path )
    $('#accordion1 a[href$="' + path + '"]').attr('class', 'activelink');
});

Please help, as I am premeturely going bald!

A: 

Why not use addClass?

$('#accordion1 a[href$="' + path + '"]').addClass('activelink');
Pointy
@Pointy - With all due respect, I don't imagine that is the issue the OP is having. Could be that OP wants to overwrite whatever classes exist. Or maybe not. Either way, using `attr()` is not invalid.
patrick dw
@patrick well you may be right, but who knows? Yes, directly blasting the class with `attr('class', 'foo')` should work, but really that's probably not the safest kind of code to run.
Pointy
Thanks for the response, I have tried that but it doesnt work either. I was thinking that the accordion process/code somehow interferes with adding the class to the nested UL as the menu section opens.
Steven
In relation to the IE question, I havent got that far yet. I am using Firefox.
Steven