After many studies, I did not find the answer. I am using the wordpress theme Twenty Twelve and it seems to load pages through ajax requests. I have a button (# header-navigation-link) that shows and hides another element on my page. It works on loading the first page without ajax calls, but when I go to another page, ajax loads it and my program can no longer find # nav-mobile-wrapper.
$(document).on('click', "#header-navigation-link", function () { $(document).find("#nav-mobile-wrapper").fadeToggle(); alert( 'Success!' ); });
A warning always appears on all ajax loaded pages, so it finds a button, not an item to show and hide. I also tried swapping two, so you press # nav-mobile-wrapper to switch # header-navigation-link, and the same thing happens just the opposite.
What am I missing for targeting # nav-mobile-wrapper in this function?
Thanks to everyone who can help!
source share