Anchors and class

Anchors and class

What am i doing wrong?

I'm trying to toggleclass on a link, with the href of the current anchor

  1. var anchor=window.location.hash;
  2. $('#nav a[href='.anchor.']').toggleClass('active');