jQuery find link that matches current page -
i have following code trying find link matches current url: $item = $('ul#ui-ajax-tabs li a').attr('href', $(location).attr('pathname'));
instead changes links current url :p
can me fix it. cheers
use query. code changes href
attributes of selected links, rather returning selection of links matching href
attribute:
$("a[href*='" + location.pathname + "']")
the [href*=..]
selector returns list of elements href
attribute contains current pathname.
another method, return elements href
contains current pathname. prop()
used instead of attr()
, relative urls correctly interpreted.
$item = $('ul#ui-ajax-tabs li a').filter(function(){ return $(this).prop('href').indexof(location.pathname) != -1; });
Comments
Post a Comment