What Does This JS Code Do?


I had a developer work on this code, not quite sure what it does as I can't talk to him anymore. This is on the navigation area of a website:

<script type="text/javascript">
  function getAbsolutePath() {
  var loc = window.location;
  var pathName = loc.pathname.substring(0, loc.pathname.lastIndexOf('/') + 1);
  return loc.href.substring(0, loc.href.length - ((loc.pathname + loc.search + loc.hash).length - pathName.length));

  $().ready(function () {
  if ($.browser.msie && $.browser.version == 10) {
  var path =  window.location.pathname;
  if (path.substr(0,1) == '/'){
  path = path.substring(1, path.length);
  if(path == ''){path = 'index.php'}
  var links = $('#menu').find('a');
  links.each(function(index) {
  if ($(this).attr('href') == path){
  if ( $(this).parent().hasClass('first')){


Open in new window

Computer GuyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Seems to be parsing the URL to see what menu item is selected and then applying on of two classes to it and everything else.
Ken ButtersCommented:
looks to me like it is executing when you first load your webpage.

Step 1 : resolve current page of the document.

if it cannot resolve the path of the webpage, it will use 'index.php' by default, and it will assign that webpage link address to path variable.

Step 2 : Loop through all of the links found inside the element id "menu", and then comparing the href attribute to the path of the current page of the document.

When the href attribute of the link inside the menu id class is equal to the path of the document, it will add a class to the element.  

if the element already has a class of first, it will add 'hover-first'
otherwise it will add a class of 'hover'.

I assume the overall intent is to add CSS styling to the hyperlinks of the menu items.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.