1

I have implemented AJAX functionality on my Wordpress site and all my menu items now load the pages in real time using AJAX feature.

How ever i dont want 1 menu item to be loaded like ajax. I can insert an additional class to that item but since it is a Wordpress based site, the menu is loaded dynamically. is there any way to create a class which voids the AJAX functionality for juts 1 Menu item.

My Code is below.

 $('.sf-menu li a').live('click', function() {    
                var toLoad = $(this).attr('href')+' #container';
        $('#container').slideUp('300',loadContent);    
        $('#load').remove();    
        $('#wrapper').append('<span id="load">LOADING...<img src="http://boala.pk/engro/wp-content/uploads/2012/07/ajax-loader.gif"></span>');    
        $('#load').fadeIn('normal');    
        window.location.hash =     $(this).attr('href').substr(0,$(this).attr('href').length-5);    
        function loadContent() {    
            $('#container').load(toLoad,'',showNewContent)    
        }    
        function showNewContent() {    
            $('#container').slideDown('400',hideLoader);    
        }    
        function hideLoader() {    
            $('#load').fadeOut('normal');    
        }    
        return false;    
    }); `
Nasir Zia
  • 564
  • 1
  • 6
  • 20

1 Answers1

1

Why can't you add an additional class to that specific menu item? In WordPress menus if you click on the Screen Options tab at the top you can enable CSS Classes and apply a class to the item you want to load normally.

You would apply a class to that specific menu item and then use the not() method in jquery to exclude the live() method being applied to that particular class.

jQuery exclude elements with certain class in selector

How do set up jquery to exclude classes in a function?

EDIT

Your code would be;

 $('.sf-menu li:not(.your-exclude-class) a').live('click', function() {  
Community
  • 1
  • 1
McNab
  • 6,767
  • 4
  • 35
  • 55
  • Could you change the class name of that particular menu and apply the menu style as it as – muthu Jul 11 '12 at 07:20
  • I cant change the class name, because its populated dynamically.. what i can do is i can add an additional class just for that menu item. But what should i write in that class? – Nasir Zia Jul 11 '12 at 07:29