
February 11th, 2013, 11:48 AM
|
 |
For POny!
|
|
Join Date: Apr 2012
Location: Amsterdam
|
|
|
Identifying active menu item
Hi guys,
I am helping out a 'friend' with a site that has some static pages due to the nature of a horrific template. Due to this I am forced to use javascript to identify active menu-items (I prefer doing it serverside but that is no option, pennywise). So i found a little script that looks like it should do the trick but it doesn't
javascript Code:
Original
- javascript Code |
|
|
|
jQuery.noConflict(); // Do something with jQuery jQuery(document).ready(function() { var pathname = window.location.pathname; var pathname = pathname.split('/'); var tester = pathname[pathname.length-1]; jQuery('#categories li a').each(function(){ var test = $(this).attr('href'); // I added this to test the values alert('test='+test+'tester='+tester); if (test == tester){ $(this).addClass('active'); } }); });
As you can see in the code It should alert 2 variables, but it doesn't alert anything. Am I missing something?
Love to hear it
P.s. the moment I go into the .each function I can't alert stuff. above that function I am able to, which for me is an indication that something is wrong there. (I have no other method of identifying errors with javascript)
Last edited by aeternus : February 11th, 2013 at 12:01 PM.
Reason: spelling
|