JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsWeb DesignJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old February 11th, 2013, 11:48 AM
aeternus's Avatar
aeternus aeternus is offline
For POny!
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2012
Location: Amsterdam
Posts: 416 aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level)aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level)aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level)aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level)aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level)aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level)aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level)aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 5 Days 4 h 56 m 43 sec
Reputation Power: 114
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
  1.  
  2. jQuery.noConflict();
  3. // Do something with jQuery
  4. jQuery(document).ready(function() {
  5.    var pathname = window.location.pathname;
  6.    var pathname = pathname.split('/');
  7.    var tester = pathname[pathname.length-1];
  8.    
  9.    jQuery('#categories li a').each(function(){
  10.        var test = $(this).attr('href');
  11. // I added this to test the values
  12.        alert('test='+test+'tester='+tester);
  13.        if (test == tester){
  14.            $(this).addClass('active');
  15.        }
  16.        
  17.    });
  18.    
  19. });


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)
__________________
PHP Tutorial

Last edited by aeternus : February 11th, 2013 at 12:01 PM. Reason: spelling

Reply With Quote
  #2  
Old February 11th, 2013, 12:10 PM
Jacques1's Avatar
Jacques1 Jacques1 is online now
pollyanna
Click here for more information.
 
Join Date: Jul 2012
Location: Germany
Posts: 1,845 Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 1 Day 9 h 4 m 28 sec
Reputation Power: 813
Hi,

you cannot use "$" when you've called jQuery.noConflict();

Check the JavaScript console of your browser. I'm sure that's exactly the error.

Reply With Quote
  #3  
Old February 11th, 2013, 12:24 PM
aeternus's Avatar
aeternus aeternus is offline
For POny!
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2012
Location: Amsterdam
Posts: 416 aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level)aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level)aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level)aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level)aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level)aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level)aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level)aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 5 Days 4 h 56 m 43 sec
Reputation Power: 114
Hi Jacques1,

Thanks! I kinda missed that dollar sign
Cheers!!

Reply With Quote
  #4  
Old February 11th, 2013, 02:05 PM
aeternus's Avatar
aeternus aeternus is offline
For POny!
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2012
Location: Amsterdam
Posts: 416 aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level)aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level)aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level)aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level)aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level)aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level)aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level)aeternus User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 5 Days 4 h 56 m 43 sec
Reputation Power: 114
If anyone wants to use this in the future here is the final script that works. (can be optimized probably )

javascript Code:
Original - javascript Code
  1.  
  2. jQuery.noConflict();
  3. // Do something with jQuery
  4. jQuery(document).ready(function() {
  5.    var pathname = window.location.pathname;
  6.    var pathname = pathname.split('/');
  7.    var tester = pathname;
  8.    
  9.    jQuery('#categories li a,#pages li a').each(function(){
  10.  
  11.        var test = jQuery(this).attr('href').split('/');
  12.        //alert(tester[1]+' | '+test[1]);
  13.        if (test[1] == tester[1]){
  14.            
  15.            jQuery(this).addClass('active');
  16.        }
  17.        
  18.    });
  19.    
  20. });
  21. //based on http://tinyurl.com/b8ujzen
  22.  

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb DesignJavaScript Development > Identifying active menu item

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap