Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery / Javascript replace <space> in anchor link with %20

I'm new to jQuery and i'm trying to write some code to go through the page and rewrite anchor links href attribute so that spaces are removed and replaced with %20.

so far i have:

$(".row a").each(function(){
  $(this).attr("href").replace(/\s/g,"%20");
});

I've tried a few variations of this with no luck.

like image 978
Ritchie Avatar asked May 12 '09 17:05

Ritchie


1 Answers

You'd be better off using the native javascript encodeURI function.

$(".row a").each(function(){
  $(this).attr( 'href', encodeURI( $(this).attr("href") ) );
});
like image 101
TJ L Avatar answered Sep 18 '22 06:09

TJ L