Add code to WordPress menu items by class

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!