How to replace element’s attr href with each ? // strip url

The code you posted will get the value as a string then properly replace the values but it immediately discards the result. You need to pass in the replaced value to attr. Try the following

$('a').each(function() {
  var value = $(this).attr('href');
  $(this).attr('href', value.replace('#/',''));
});​

Leave a Comment