Search code examples
jqueryanchorrel

jquery and rel attribute of link


I try to add a class to a link with jquery

<a rel="/Career/" href="/Career/"></a>

$('a[rel=' + window.location.pathname + ']').addClass('current');

The above command works well with href, but not rel. I cannot use href and look for a good alternative. I think syntax maybe wrong.

$('a[rel="' + window.location.pathname + '"]').addClass('current');

does not work too


Solution

  • Just use it like:

    $('a[rel="' + window.location.pathname + '"]').addClass('current');
    

    only adding "