> From: Michael Geary > > var $navleft = $("#navleft"); > $navleft.attr( "href", $navleft.attr("href").slice(0,-1) + '0' ); > > Or even this (which is probably the way I'd code it myself): > > var navleft = $("#navleft")[0]; > navleft.href = navleft.href.slice(0,-1) + '0';
I may have been a bit too clever there: navleft.href isn't the same as $navleft.attr('href'). jQuery's attr() method calls .getAttribute() on the DOM element, so it's like doing: navleft.getAttribute('href') That's not the same thing as navleft.href, particularly in the case where the href is a relative URL. navleft.getAttribute('href') returns the actual value of the href attribute. navleft.href converts the href value to an absolute URL. So, if your page is at http://www.example.com/test.html and you have a relative URL in href such as "/test/foobar/", then .getAttribute('href') will return "/test/foobar/", but .href will return "http://www.example.com/test/foobar/". In practical terms it may not make much difference - after all both the relative and absolute URLs will point to the same place - but if your code was expecting to see the actual value of the href attribute, .href would not be the way to get it. -Mike