O'Reilly logo

Mastering jQuery UI by Vijay Joshi

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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(); ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required