$('a').each(function() { $(this).attr('title', $(this).text()); });
Keep in mind, though, that an anchor might have an image inside, rather than text. I doubt it'd be an issue. I guess jquery would simply set it to the empty string. On Wed, Mar 4, 2009 at 6:11 PM, Jonny Stephens <goo...@bloog.co.uk> wrote: > > I want to generate title attributes from existing anchor text, e.g. > > <a href="foo.html">Foo Foo</a> > > becomes > > <a href="foo.html" title="Foo Foo">Foo Foo</a> > > The code below works in FF3 with Firebug reporting no errors, but > Safari reports a parsing error. IE is no go. > > $('a').attr('title' , function() $(this).text()); > > adding curly brackets clears the parsing error in Safari but doesn't > function in any browser. > > $('a').attr('title' , function() { $(this).text() } ); > > I must be missing something simple here.