How to convert a Title to a URL slug in jQuery?

I have no idea where the ‘slug’ term came from, but here we go: function convertToSlug(Text) { return Text.toLowerCase() .replace(/ /g, ‘-‘) .replace(/[^\w-]+/g, ”); } The first replace method will change spaces to hyphens, second, replace removes anything not alphanumeric, underscore, or hyphen. If you don’t want things “like – this” turning into “like—this” then … Read more