This seems to work: $('a').each(function() { $(this).attr('href','path/to/' + RegExp("[^#]+$").exec($(this).attr ('href')) + '.html'); });
On Mar 15, 7:03 pm, Jonny Stephens <goo...@bloog.co.uk> wrote: > Oops. Wrote too soon. > > Works fine for a single anchor. With multiples, all receive the same > href value as the first. > > Needs an .each() somewhere? > > On Mar 15, 5:44 pm, Jonny Stephens <goo...@bloog.co.uk> wrote: > > > Thanks Brad, that's perfect! > > > Jonny > > > On Mar 15, 5:29 pm, Brad <nrmlcrpt...@gmail.com> wrote: > > > > There is probably a more concise way to do this, but I'll break down > > > the steps > > > > // regular expression pattern to get the hash value > > > var patt = new RegExp("[^#]+$"); > > > > // The href of your attribute. This is a generic example, you will > > > // probably need to provide a more specific jQuery selector to get the > > > "a" you > > > // want to manipulate > > > var href = $('a').attr('href'); > > > > // search for hash value in href > > > var hashval = patt.exec(href); > > > > // Again, you'll probably need a more specific jQuery selector > > > // overwrite the existing href of the selected "a" > > > $('a').attr('href','path/to/' + hashval + '.html'); > > > > On Mar 15, 10:22 am, Jonny Stephens <goo...@bloog.co.uk> wrote: > > > > > Can anyone provide guidance on how to modify href attributes in this > > > > way: > > > > > Markup: <a href="22_foo.html#foo22-name"> > > > > > Modify to: <a href="path/to/foo22-name.html"> > > > > > i.e. removing everything up to and including the #, prepending a fixed > > > > path value and appending ".html" > > > > > Thanks > > > > > Jonny