var id = parseInt(document.location.pathname.replace(/^\//, '').split('/')[1], 10); var baseEl = document.getElementById('baseHref'); if (!isNaN(id)) { baseEl.setAttribute('href', baseEl.getAttribute('href') + '/' + id); }