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

How can I edit my VIM config so that Vim treats ".ejs" files the same as it currently treats my html files? -

Python __call__ special method practical example -