So yes, by far you should use the new event handlers instead of adding attributes to your html tags. (so your second method, in the footer)
The reason your footer code didn’t work is because you didn’t quite figure out how to transfer from the attribute to the handler form…
When you say onclick="toggle_visibility('sub-menu');"
the “onclick=” is an html attribute and anything inside the double-quotes after that is javascript code.
So to make that into a jquery click handler, you just need the javascript code part:
<script type="text/javascript">
$(function() { // <--- make sure we don't run our code before the page is ready!
$('.res-clearfix li.dropdown a').click(function() {
toggle_visibility('sub-menu');
});
});
</script>
Hope this helps!
Related Posts:
- Change hover to onclick on menu
- Display a portion/ branch of the menu tree using wp_nav_menu()
- Add Javascript to WordPress Menu
- Add custom menu item using wp_nav_menu_items filter
- how to create a menu with all sub categories?
- Add separator to admin submenu
- Display only page specific sub menu items using Custom Walker
- Add a .last class to the last in each ul.sub-menu
- Multi Level Bootstrap Navigation Menu in WordPress
- Add class to top level menu item if it has multiple child levels
- How show sub menu only using wp_nav_menu()
- Show only 2nd level of navigation depending on active navigation
- Simple Navigation Walker – Wrapper-class around first sub-menu
- How to get a separate child menu?
- Link after WordPress
- Set one or more menus as a submenus of another menu
- cannot get global $menu value in form request
- Show Sub Menu on click and not hover
- Custom menu with additional logic for display
- Event listener callback returns undefined element
- Mobile navigation javascript problem
- Add Different Class on Different Ul in twenty-twentyone theme
- insert an HTML element if there is a submenu only
- Cannot collapse a responsive menu in WordPress
- How can I creat custom menu with bootstrap
- wp_nav_menu container style args
- Bootstrap Theme Migrated to WordPress
- WordPress + Bootstrap: Replace primary navigation menu on mobile?
- Add “onclick” option to header menu item
- having a page in multi sub-menu and match current-menu-item
- How can I click the parent menu then redirect to a special URL?
- Add CSS Class to WordPress Menu Item Dependent on the Page the User is Visiting
- Why my dropdown menu is effecting main menu?
- Homepage Menu Link Won’t Function
- How to create a mobile menu full screen overlay using Understraps Bootstrap 4 theme
- Menu walker: how to tell if a sub menu contains submenus?
- Creating navigation out of specific IDs and their children?
- Where to place a svg chevron down in my custom walker?
- Add href to tag in nav menu for mobile
- calling JS to custom menu design
- javascript i wrote not working, can’t figure out why [closed]
- Getting parent object_id of child menu items in WordPress menu
- Incorrect Behavior on WordPress Main Menu
- How to access into the description of a sub menu
- Generate Submenu based on Parent Page using If Statement
- WordPress menu issue after update
- Product categories are mixed when creating menu
- Importing large product categories into wordpress menu
- Adding span to a particular text in an menu item
- Displaying a part of a menu containing the page the user is currently viewing and only it’s immediate children
- I can’t correctly display menu
- How can I make menu items into two seperate buttons with different functions?
- how to create pages and link them to a menu
- Conditional Nav Menu Inside Nav Menu Across Multisite Sites
- How to separate sub-menu output and keep associated with parent
- Has there been any improvements to wp’s menu handling?
- How to sort a sub-menu, generated with get_pages(), by the page order instead of alphabetically?
- Menu Details Output in Javascript [closed]
- Reveal hidden submenus on page load – Twenty Fifteen theme
- Always show wordpress submenu on responsive header menu
- Show Child of Parent Page including all other parents
- Add a Submenu from Another Submenu in a Custom Theme
- Showing a link with Javascript based on log-in status
- How to display list of child pages with parent in wordpress?
- nav_menu: how to force a subpage switching on the parent menu
- Use menu structure for permalinks
- Adding two submenus to a menu
- How do i keep my current page menu highlighted on pagination?
- How to create a menu super voice in WP?
- Add tooltips with image in WordPress Menu?
- Building Menus with the latest posts included
- Menu support for touch devices
- How to add drop down sub menu from database fields in the particular menu slug
- collapse twenty twelve submenu in mobile version
- Display all submenus
- Change sub-menu css class
- How do I get my nav menu to show sub pages?
- Adding Sub Menu In a theme which Do not have Menu Options
- ID of parent Menu
- wp_nav_menu changed to wp_page_menu
- Should I custom code drop down menus or use a wordpress plugin?
- How can I alter the visible menu according to which level I am on [closed]
- How was this menu system created?
- How to display a submenu as a popup when clicking a button?
- how to mage the submenu open on wordpress active page
- Display sub menus as separate lists
- nav tag wrapping around dropdown
- Jquery dropdown menus working locally, but not in WordPress [duplicate]
- Changing when mobile menu is displayed
- WordPress menu is getting automatically nested
- What is the best way to incorporate responsive dropdown navigation menu into custom theme?
- How can I only show one responsive menu on mobile devices?
- Active Navigation Class Based on URL on icon
- Add acf custom fields so sub item in menus
- Give custom class names to WP nav sub-menu
- Nav walker bootstrap: Display 3rd level and 4th level in dropdown menu
- There is no option to click the button in header only on some pages
- wp_nav_menu parent in submenu
- Override theme hamburger menu to work without javascript (noscript)
- How to add toggle-able DOM element after nav menu item?