Hi there,   I'm trying to build a UI with different components using tweenlite to add/remove items from the viewport.   As I add more elements I'm finding that alot of code is getting repeated in my functions and although the animations applied to each element are slightly different, the principal behind them is the same, i.e. Add / Remove a class to an element with a click event and tween the element accordingly. E.g. (function openMainMenu() { var $openMenu = $('.openMenu'), $menuContainer = $('#jsMainMenu'); $openMenu.click(function(e) { e.preventDefault(); $(".openMenu").addClass("is--hidden"); $(".openMenu").removeClass("is--active"); $(".closeMenu").addClass("is--active"); $(".closeMenu").removeClass("is--hidden"); // slide menu in TweenLite.to($menuContainer, 0.2, {position:"fixed", zIndex:"998", display:"block", delay:0.1, right:"0%", bottom:"0%", ease:Power2.easeOut}); console.log("Menu Inview"); }); })(); (function closeMainMenu() { var $closeMenu = $('.closeMenu'), $menuContainer = $('#jsMainMenu'); $closeMenu.click(function(e) { e.preventDefault(); $(".openMenu").addClass("is--active"); $(".openMenu").removeClass("is--hidden"); $(".closeMenu").addClass("is--hidden"); $(".closeMenu").removeClass("is--active"); // slide menu out TweenLite.to($menuContainer, 0.2, {display:"none", zIndex:"0", delay:0.1, right:"-100%", ease:Power2.easeOut}); console.log("Menu Hidden"); }); })(); So clicking the button with class 'openMenu' hides the button, displays the close button and tweens the menu container into view. If you check the codepen demo you'll see a very similar pair of functions for a search container, and I'd also like to add an off-canvas contact form, search bar etc...     What I'd like to know is how best to restructure my code so that 1. large portions of code to not get repeated, and, more importantly, 2. How to chain events so that if one element is active e.g. Main Menu, clicking outside of it or clicking Search Tours or another button activates the 'close' function on the main menu as well as opening search tours - or whatever else I add to the UI   Many thanks in advance for any help  See the Pen OyePPg by mulegoat (@mulegoat) on CodePen