I have the following code that is trying to find a link that matches the current url: $item = $('ul#ui-ajax-tabs li a').attr('href', $(location).attr('pathname')); but instead it changes all the links to the current url 😛
Can anyone help me fix it. Cheers
Use this query. Your code changes all
hrefattributes of the selected links, rather than returning a selection of links with a matchinghrefattribute:The
[href*=..]selector returns a list of elements whosehrefattribute contains the current pathname.Another method, return all elements whose
hrefcontains the current pathname.prop()is used instead ofattr(), so that relative URLs are also correctly interpreted.