var html = \"\"+title+\"
\";
document.write(title.replace(/ /g,\"-\"));
html+= \'
ehdv's answer gets you 90% of the way there. I just wanted to clarify where the code he suggested would go within your code, and it wouldn't look right in a comment.
var html = "" + title + "
";
title = title.replace(/\s/g , "-");
html+= '';
This assumes that you DON'T want dashes in the div, but you DO in the URL.
And if you also want to replace multiple spaces that come immediately one after another with a SINGLE dash instead of ending up with double dashes in your title, use this instead:
var html = "" + title + "
";
title = title.replace(/\s+/g , "-");
html+= '
I'd also like to mention that you're not closing your div. Maybe you just didn't include that part of your code but it's worth mentioning. There's also an unnecessary \ in your string. It's not hurting anything, but it's not needed. Maybe your code is meant to look like this:
var html = "" + title + "";
title = title.replace(/\s/g , "-");
html+= '