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

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -