Substitua todos os espaços por traço em javascript

title = title.replace(/\s/g , "-");
var html = "<div>" + title + "</div>";
// ...
Horrible Hamster