Any smart way of doing a \"root\" based path referencing in JavaScript, just the way we have ~/ in ASP.NET?
Kamarey's answer can be improved to support a dynamic base path:
This will ensure a correct root path regardless of deployment configuration.
To be fair, this doesn't answer the original question, but it elimiates most needs for getting the root path from javascript. Simply use relative URL's everywhere, without prefixing with slash.
Should you still need to access it from javascript, add an id attribute and use document.getElementFromId() as MiffTheFox suggested - but on the base-tag.