Replace Spaces in href with hyphen using jQuery

by ashleycam3ron

HTML

<div class="entry-content">

<a target="_blank" href="./some link without hyphens who knows why.pdf">Why would someone create a page of links in which the links have spaces and not hypens</a>

</div>

JavaScript

jQuery(document).ready(function() {
  jQuery('.entry-content a').each(function() {
    jQuery(this).attr('href', jQuery(this).attr("href").replace(/\s/g, "-"));
  });
});

/* copy the output html of your element with all of the new links and remove this code when finished */