Wednesday, 21 August 2013

replace matching text in hyperlink herf

replace matching text in hyperlink herf

What im trying to do is find all hyperlinks that have a href like this
herf="/grade4/chapter1.html" and replace the chapter word with
href="grade4/chapter_af1.html"
i have tried a few jquery tricks but have had no luck
$('a').each( function() {
var $this = $(this);
var href = $this.attr('href').replace(/\chapter/,'chapter_af');
$this.attr('href', href );
});

No comments:

Post a Comment