How to do Initial Caps With Javascript/jQuery
<p>I have a Dynamic Breadcrumb set up with JavaScript. All I want is to do Initial Caps for each word.</p>

<p>Example:
Home > Some > Page</p>

<p>Currently I have them all converted to lowercase and have removed all - from the strings in pages that have multiple words. I just need to convert the string to Initial Caps. Here is my code that I have working so far:</p>

<pre><code>var path = "",
    href = document.location.href,
    domain =  href.match(/:\/\/(.[^/]+)/)[1],
    replacedomain = 'http://' + domain + '/',
    s = href.replace(/-/gi, " ").split("/"),
    lastElement = document.location.href.split('/').splice(-1,1);



for (var i = 2; i &lt; (s.length - 1); i++) {
    path += "&lt;a class='bc' href=\"" + href.substring(0, href.indexOf("/" + s[i]) + s[i].length + 1) + "/\"&gt;" + s[i] + "&lt;/a&gt; &gt;  ";

    if (i &gt; 0) { 
       breadcrumb = path;  
    }
}


i = s.length - 1;
breadcrumb += "&lt;span&gt;" + s[i] + "&lt;/span&gt;";


var breadcrumbl = breadcrumb.toLowerCase(),
    domain =  breadcrumbl.match(/:\/\/(.[^/]+)/)[1],
    breadcrumb2 = breadcrumbl.replace(domain, "").replace(domain, ""),
    breadcrumbs = breadcrumb2,
    url = '&lt;a href="/"&gt;Home&lt;/a&gt;' + breadcrumbs;

document.getElementById('breadcrumb1').innerHTML=url;
</code></pre>

<p>I think the solution is with a regular expression but I'm not good at writing them and I'm having a hard time with the concept. Also if anyone thinks this script can be optimized further your feedback is welcome. I'll will make variable names more semantic for production.</p>
