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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.