Adding event handlers in the init method

The init method is the first method of the myReddit object that is called. Since this is a starting point for us, let's begin by creating the tabs and attaching all the event handlers that will be used later in the code.

Tip

It is good practice to define all event handlers in one place. Different event handlers scattered all over the code are bad for readability, as well as for debugging the code later.

Look for the init method in the myReddit.js file and write the following code to set up tabs and event handlers:

$( "#redditTabs" ).tabs(); $('#addNewSubreddit').button(); $('#tabList').on('click', '.ui-icon-close', function() { var tabPanelContainer = $(this).prev('a').attr('href'); $(this).parent('li').remove(); ...

Get Mastering jQuery UI now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.