jQuery generate breadcrumbs from url?

Evanss picture Evanss · Jun 22, 2011 · Viewed 7.5k times · Source

Is there a way of getting jQuery to generate breadcrumbs on a page from the url?

So if the site url was: mysite.com/sec1/sec2/page

The breadcrumbs would be something like: Home > Sec1 > Sec2 > Page

Thanks

Answer

Sjoerd picture Sjoerd · Jun 22, 2011
var url = 'mysite.com/sec1/sec2/page'; // = location.href
var parts = url.split('/');
parts[0] = 'Home';
var breadcrumb = parts.join(' > ');
$('#breadcrumb').html(breadcrumb);