views:

32

answers:

2

Hi,

I want to add class to <a>, what has some url. For exampe :

$(document).ready(function() {

    var pathname = window.location.pathname;        
    $(".navholder ul li a").each(function() {
        $(this).addClass('sel');
    });

});

I want to add "sel" class to <a> what has href=pathname.

Theoretically something like this :

$(".navholder ul li a").attr('href', pathname).addClass('sel');

Thanks!

+1  A: 

Take a look at the jQuery selector syntax:

$('.navholder ul li a [href=\\/foo\\/bar]').addClass('sel');

Note that you must escape / in jQuery expressions, and double-escape if it is a string literal.

gahooa
+2  A: 

Use this line:

$(".navholder ul li a[href='"+ pathname +"']").addClass('sel');

mjangda