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 separator to admin submenu
- Display only page specific sub menu items using Custom Walker
- Add class to top level menu item if it has multiple child levels
- How show sub menu only using wp_nav_menu()
- Simple Navigation Walker – Wrapper-class around first sub-menu
- How to get a separate child menu?
- Exclude one item from wp_list_pages( $args );
- How to drag multiple menu items at once in WordPress?
- Customizing the a tag with Semantic UI
- Put a wp_nav_menu inside another one
- Generate a Menu that displays all child pages of top level parent
- Check if wp_nav_menu items have submenus
- Automatically Add New Tags to Sub-menu
- Nav walker, bootstrap: Display 3rd level items under 2nd level
- how to only add a top-level admin menu without it creating a sub-level-menu
- how to automatically generate hierarchical menus from hierarchy of pages?
- Merge two separate WP menus into one in Mobile view
- Programmatically adding menu items function replicates in multiple menus
- Sub-Pages only of menu items in current branch using a custom menu
- wp_list_pages: only show subpages on the parent page?
- How to have custom menu Item CSS Classes for wp_page_menu() or wp_list_pages()
- WordPress sub-menu items suddenly not showing
- No “current-menu-ancestor” class added when browsing an archive page
- Main Menu and Sub Menu Items for Footer
- How to construct a custom html for submenus
- Check if menu id = $specific_id – then insert specific
- I am facing a problem with the navigation menu of my website
- add_submenu_page function to show videos table
- How do I add recent posts to the menu?
- How to add ID attribute to each submenu?
- From a page, is it possible to find entry’s “menu_item_parent”?
- WordPress menu link not working
- Automatically list top level menu item child pages
- Highlight current post ancestor parent menu items
- How to retrieve parent menu item name of current submenu item
- Check if menu_item has children or has parent
- Creating a menu containing categories and authors
- Change submenu markup
- getting the current sub item out of total sub items in a given dropdown (custom walker)
- Show WordPress Menu On External Site
- How to highlight 1st level menu item based on actual page
- Adding sub-menu item makes parent item unclickable
- Insert a div class inside wordpress menu
- Add Labels to Admin Menu ( How To )
- Problem adding ‘has-children’ class to wp_nav_menu
- How to buid wordpress menu with auto width sub-menu items in dropdown menu without any items sharing one line [closed]
- Adding toggle-able element after menu item
- Add (grand)child pages automatically to nav menu
- Creating menu always gives error A name is required for this term
- Twenty Fifteen: Change navigation menu behavior
- Get parents child pages
- Replace anchor tag with span tag
- If current menu item is child or parent with child?
- Controlling sub-menu within sub-menu
- An alternative to WordPress’s built-in menu functionality
- Dropdown primary navigation menu not working
- Is there any way to change the CSS class applied to 2nd level sub menu ul’s?
- Link after WordPress
- Event listener callback returns undefined element
- Add Different Class on Different Ul in twenty-twentyone theme
- insert an HTML element if there is a submenu only
- How can I creat custom menu with bootstrap
- wp_nav_menu container style args
- WordPress + Bootstrap: Replace primary navigation menu on mobile?
- 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
- Menu walker: how to tell if a sub menu contains submenus?
- calling JS to custom menu design
- Getting parent object_id of child menu items in WordPress menu
- Incorrect Behavior on WordPress Main Menu
- Generate Submenu based on Parent Page using If Statement
- WordPress menu issue after update
- Importing large product categories into wordpress menu
- 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
- Conditional Nav Menu Inside Nav Menu Across Multisite Sites
- How to sort a sub-menu, generated with get_pages(), by the page order instead of alphabetically?
- Reveal hidden submenus on page load – Twenty Fifteen theme
- Add a Submenu from Another Submenu in a Custom Theme
- 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?
- Menu support for touch devices
- collapse twenty twelve submenu in mobile version
- Change sub-menu css class
- ID of parent Menu
- Should I custom code drop down menus or use a wordpress plugin?
- 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]
- What is the best way to incorporate responsive dropdown navigation menu into custom theme?
- Active Navigation Class Based on URL on icon
- Give custom class names to WP nav sub-menu