Hi Kris,

The problem is that $(this) is referencing something other than the link at that point -- either some enclosing method or the window object. You can get around this by using a callback function as the second argument of .attr() :

$("#content_main a").attr('href', function() {
  return 'cms/' + $(this).attr('href');
});



--Karl

____________
Karl Swedberg
www.englishrules.com
www.learningjquery.com




On Dec 10, 2008, at 9:59 AM, Kris wrote:


I'm trying to use the below code to prefix all href's with 'cms/'...

[code]
$("#content_main a").attr('href', 'cms/' + $(this).attr('href'));
[/code]

I end up with href's which look like this "cms/undefined". I guess I
need to get $(this).attr('href') to return a string instead of a
JQuery object?

Many thanks, K.


Reply via email to